Sha256: 7cd7a745b5dd49648557590c99d524775bc7ff42c9fbf63652efafefccd1ffe5

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

require 'spec_helper'

describe Spotlight::Role 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

2 entries across 2 versions & 1 rubygems

Version Path
blacklight-spotlight-0.1.0 spec/models/spotlight/role_spec.rb
blacklight-spotlight-0.0.3 spec/models/spotlight/role_spec.rb