2010-05-29 13:20:59 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe RoleModel::Roles do
|
|
|
|
|
|
|
|
let(:model_instance) { Class.new.new }
|
|
|
|
let(:array) { [:foo, :bar] }
|
|
|
|
subject { RoleModel::Roles.new(model_instance, array) }
|
2010-10-10 15:25:47 +02:00
|
|
|
before(:each) do
|
|
|
|
model_instance.stub(:roles=)
|
|
|
|
end
|
2010-05-29 13:20:59 +02:00
|
|
|
|
2017-06-20 16:02:07 -07:00
|
|
|
it { subject.model_instance.should equal(model_instance) }
|
2010-05-29 13:20:59 +02:00
|
|
|
it { should include(:foo, :bar) }
|
2010-05-29 23:29:27 +02:00
|
|
|
it { should respond_to(:each) }
|
2010-05-29 13:20:59 +02:00
|
|
|
|
|
|
|
describe "#<<" do
|
|
|
|
it "should add the given element to the model_instance.roles by re-assigning all roles" do
|
2010-05-29 23:29:27 +02:00
|
|
|
model_instance.should_receive(:roles=).with(array_including(:foo, :bar, :baz))
|
2010-05-29 13:20:59 +02:00
|
|
|
subject << :baz
|
|
|
|
end
|
|
|
|
end
|
2010-09-26 12:18:55 +08:00
|
|
|
|
2010-10-10 15:25:47 +02:00
|
|
|
describe "#add" do
|
|
|
|
it "should add the given element to the model_instance.roles by re-assigning all roles" do
|
|
|
|
model_instance.should_receive(:roles=).with(array_including(:foo, :bar, :baz))
|
|
|
|
subject.add(:baz)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#merge" do
|
|
|
|
it "should add the given enum to the model_instance.roles by re-assigning all roles" do
|
|
|
|
model_instance.should_receive(:roles=).with(array_including(:foo, :bar, :baz, :quux))
|
|
|
|
subject.merge([:baz, :quux])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-26 12:18:55 +08:00
|
|
|
describe "#delete" do
|
|
|
|
it "should delete the given element to the model_instance.roles by re-assigning all roles" do
|
2010-10-10 15:06:28 +02:00
|
|
|
model_instance.should_receive(:roles=).with(subject)
|
2010-09-26 12:18:55 +08:00
|
|
|
subject.delete :foo
|
2010-10-10 15:06:28 +02:00
|
|
|
subject.should_not include(:foo)
|
2010-09-26 12:18:55 +08:00
|
|
|
end
|
|
|
|
end
|
2010-10-10 15:25:47 +02:00
|
|
|
|
|
|
|
describe "#subtract" do
|
|
|
|
it "should remove the given enum to the model_instance.roles by re-assigning all roles" do
|
|
|
|
model_instance.should_receive(:roles=).with(subject)
|
|
|
|
subject.subtract([:foo, :bar])
|
2017-06-20 16:02:07 -07:00
|
|
|
expect(subject.size).to be 0
|
2010-10-10 15:25:47 +02:00
|
|
|
end
|
|
|
|
end
|
2010-05-29 13:20:59 +02:00
|
|
|
end
|