Sha256: 0c6309e811bdc29bd646a4d409a830f075a819fe99f6d8ed7921775c9ef14f72

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'

describe Spotlight::Role, :type => :model do
  describe "validations" do
    subject { Spotlight::Role.new(args) }
    describe "with nothing" do
      let(:args) { {user_key: ''} }
      it "should not be valid" do
        expect(subject).not_to be_valid
        expect(subject.errors.messages).to eq({:role=>["is not included in the list"], :user_key=>["can't be blank"]})
      end
    end
    describe "with user_key" do
      let (:user) { FactoryGirl.create(:user)}
      describe "that doesn't point at a user" do
        let(:args) { {role: 'curator', user_key: 'bob'} }
        it "should not be valid" do
          expect(subject).not_to be_valid
          expect(subject.errors.messages).to eq({:user_key=>["User must sign up first."]})
        end
      end
      describe "that points at a user" do
        let(:args) { {role: 'curator', user_key: user.email} }
        it "should be valid" do
          expect(subject).to be_valid
          expect(subject.errors.messages).to be_empty
        end
      end
      describe "that points at a user with an existing role" do
        before { Spotlight::Role.create!(role: 'curator', user: user) }
        let(:args) { {role: 'curator', user_key: user.email} }
        it "should be valid" do
          expect(subject).not_to be_valid
          expect(subject.errors.messages).to eq({:user_key => ["already a member of this exhibit"]})
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
blacklight-spotlight-0.4.1 spec/models/spotlight/role_spec.rb
blacklight-spotlight-0.3.1 spec/models/spotlight/role_spec.rb
blacklight-spotlight-0.3.0 spec/models/spotlight/role_spec.rb
blacklight-spotlight-0.2.0 spec/models/spotlight/role_spec.rb