spec/zertico/delegator_spec.rb in zertico-1.3.0 vs spec/zertico/delegator_spec.rb in zertico-2.0.0.alpha.1
- old
+ new
@@ -1,56 +1,105 @@
require 'spec_helper'
describe Zertico::Delegator do
let(:user) { User.new }
- let(:user_delegator) { UserDelegator.new(user) }
+ let(:product) { Product.new }
+ let(:user_delegator) { UserDelegator.new }
context 'on a namespaced delegator and interface model' do
it 'should find the interface model' do
- Person::ProfileDelegator.send(:interface_class).should == Person::Profile
+ expect(Person::ProfileDelegator.send(:interface_class)).to eq(Person::Profile)
end
it 'should return a valid instance variable name' do
- Person::ProfileDelegator.send(:interface_name).should == 'profile'
+ expect(Person::ProfileDelegator.send(:interface_name)).to eq('profile')
end
end
context 'on a namespaced delegator and non namespaced interface model' do
it 'should find the interface model' do
- Admin::UserDelegator.send(:interface_class).should == User
+ expect(Admin::UserDelegator.send(:interface_class)).to eq(User)
end
it 'should return a valid instance variable name' do
- Admin::UserDelegator.send(:interface_name).should == 'user'
+ expect(Admin::UserDelegator.send(:interface_name)).to eq('user')
end
end
context 'on a non namespaced delegator and non namespaced interface model' do
it 'should find the interface model' do
- UserDelegator.send(:interface_class).should == User
+ expect(UserDelegator.send(:interface_class)).to eq(User)
end
it 'should return a valid instance variable name' do
- UserDelegator.send(:interface_name).should == 'user'
+ expect(UserDelegator.send(:interface_name)).to eq('user')
end
end
+ describe '.new' do
+ context 'without params' do
+ it "should initialize an object based on delegator's name" do
+ expect(UserDelegator.new.interface).to be_an_instance_of(User)
+ end
+ end
+
+ context 'with an object as param' do
+ it 'use this object' do
+ expect(UserDelegator.new(product).interface).to be_an_instance_of(Product)
+ end
+ end
+ end
+
describe '.find' do
before :each do
- User.stub(:find => user)
+ allow(User).to receive(:find).and_return(user)
end
it 'should return an delegator' do
- UserDelegator.find(3).should be_an_instance_of(UserDelegator)
+ expect(UserDelegator.find(3)).to be_an_instance_of(UserDelegator)
end
end
describe '#interface' do
before :each do
- User.stub(:find => user)
+ allow(User).to receive(:find).and_return(user)
end
it 'should return the interface object' do
- UserDelegator.find(3).interface.should == user
+ expect(UserDelegator.find(3).interface).to eq(user)
+ end
+ end
+
+ describe '#interface=' do
+ before :each do
+ user_delegator.interface = product
+ end
+
+ it 'should set the interface object' do
+ expect(user_delegator.interface).to eq(product)
+ end
+ end
+
+ describe '.interface_name' do
+ it 'should return the interface name' do
+ expect(UserDelegator.interface_name).to eq('user')
+ end
+ end
+
+ describe '.interface_class' do
+ it 'should return the interface name' do
+ expect(UserDelegator.interface_class).to eq(User)
+ end
+ end
+
+ describe '#interface_name' do
+ it 'should return the interface name' do
+ expect(user_delegator.send(:interface_name)).to eq('user')
+ end
+ end
+
+ describe '#interface_class' do
+ it 'should return the interface name' do
+ expect(user_delegator.send(:interface_class)).to eq(User)
end
end
end
\ No newline at end of file