spec/zertico/permitted_params_spec.rb in zertico-2.0.0.alpha.3 vs spec/zertico/permitted_params_spec.rb in zertico-2.0.0.beta.1

- old
+ new

@@ -1,20 +1,39 @@ require 'spec_helper' describe Zertico::PermittedParams do let(:user) { User.new } - let(:params) { ActionController::Parameters.new(:user => { :id => 1, :name => "name" }) } + let(:params) { ActionController::Parameters.new(:id => 1, + :user => { :first_name => "first_name", + :last_name => "last_name" }) } let(:user_permitted_params) { UsersPermittedParams.new(params) } + let(:zertico_permitted_params) { Zertico::PermittedParams.new(:zertico => { :id => 1, :name => "name" }) } describe '#create' do - it "should ignore the id" do - expect(user_permitted_params.create).to eq({ 'name' => 'name' }) + context 'on a custom PermittedParams' do + it "should ignore the id" do + expect(user_permitted_params.create).to eq({ 'first_name' => 'first_name' }) + end end + + context 'on Zertico::PermittedParams' do + it "should accept all attributes of the hash" do + expect(zertico_permitted_params.create).to eq({ :id => 1, :name => 'name' }) + end + end end describe '#update' do - it "should ignore the name" do - expect(user_permitted_params.update).to eq({ 'id' => 1 }) + context 'on a custom PermittedParams' do + it "should accept id and a hash of attributes" do + expect(user_permitted_params.update).to eq({ "last_name" => "last_name" }) + end + end + + context 'on Zertico::PermittedParams' do + it "should accept all attributes of the hash" do + expect(zertico_permitted_params.update).to eq({ :id => 1, :name => 'name' }) + end end end describe '.interface_class' do it 'should return the interface singular name ' do \ No newline at end of file