spec/zertico/service_spec.rb in zertico-0.5.2 vs spec/zertico/service_spec.rb in zertico-0.5.3
- old
+ new
@@ -1,22 +1,31 @@
require 'spec_helper'
describe Zertico::Service do
let(:controller) { UserController.new }
let(:admin_controller) { Admin::UserController.new }
+ let(:profile_controller) { Person::ProfileController.new }
let(:object) { Object.new }
- context 'should find the interface class' do
- it 'on a non namespaced controller' do
- controller.send(:interface_class).should == User
+ context 'on a namespaced controller and interface model' do
+ it 'should find the interface model' do
+ profile_controller.send(:interface_class).should == Person::Profile
end
+ end
- it 'on a namespaced controller' do
+ context 'on a namespaced controller and non namespaced interface model' do
+ it 'should find the interface model' do
admin_controller.send(:interface_class).should == User
end
end
+ context 'on a non namespaced controller and non namespaced interface model' do
+ it 'should find the interface model' do
+ controller.send(:interface_class).should == User
+ end
+ end
+
context '#all' do
before :each do
controller.stub_chain(:interface_name, :pluralize, :to_sym).and_return(:users)
controller.stub_chain(:interface_class, :all).and_return([])
end
@@ -26,60 +35,60 @@
end
end
context '#build' do
before :each do
- controller.stub_chain(:interface_name, :to_sym).and_return(:user)
+ controller.stub_chain(:interface_name, :to_sym).and_return(:person)
controller.stub_chain(:interface_class, :new).and_return(object)
end
it 'should return a new object' do
- controller.build.should == { :user => object }
+ controller.build.should == { :person => object }
end
end
context '#find' do
before :each do
- controller.stub_chain(:interface_name, :to_sym).and_return(:user)
+ controller.stub_chain(:interface_name, :to_sym).and_return(:person)
controller.stub_chain(:interface_class, :find).with(1).and_return(object)
end
it 'should return the specified object' do
- controller.find(1).should == { :user => object }
+ controller.find(1).should == { :person => object }
end
end
context '#generate' do
before :each do
- controller.stub_chain(:interface_name, :to_sym).and_return(:user)
+ controller.stub_chain(:interface_name, :to_sym).and_return(:person)
controller.stub_chain(:interface_class, :create).with({}).and_return(object)
end
it 'should return the created object' do
- controller.generate({}).should == { :user => object }
+ controller.generate({}).should == { :person => object }
end
end
context '#modify' do
before :each do
- controller.stub(:find).with(1).and_return({ :user => object })
+ controller.stub(:find).with(1).and_return({ :person => object })
object.stub(:update_attributes).with({}).and_return(true)
- controller.stub_chain(:interface_name, :to_sym).and_return(:user)
+ controller.stub_chain(:interface_name, :to_sym).and_return(:person)
end
it 'should return the updated object' do
- controller.modify(1, {}).should == { :user => object }
+ controller.modify(1, {}).should == { :person => object }
end
end
context '#delete' do
before :each do
- controller.stub(:find).with(1).and_return({ :user => object })
+ controller.stub(:find).with(1).and_return({ :person => object })
object.stub(:destroy).and_return(true)
- controller.stub_chain(:interface_name, :to_sym).and_return(:user)
+ controller.stub_chain(:interface_name, :to_sym).and_return(:person)
end
it 'should return the destroyed object' do
- controller.delete(1).should == { :user => object }
+ controller.delete(1).should == { :person => object }
end
end
end
\ No newline at end of file