spec/lib/scopes_spec.rb in api_resource-0.6.21 vs spec/lib/scopes_spec.rb in api_resource-0.6.22

- old
+ new

@@ -1,19 +1,20 @@ require 'spec_helper' describe ApiResource::Scopes do - + before(:all) do ScopeResource.class_eval do scope :no_arg, {} scope :one_arg, {id: :req} scope :one_array_arg, {ids: :req} scope :two_args, {page: :req, per_page: :req} scope :opt_args, {arg1: :opt} scope :req_and_opt_args, {arg1: :req, arg2: :opt} scope :var_args, {ids: :rest} scope :mix_args, {id: :req, vararg: :rest} + scope :date_scope, {start_date: :req, end_date: :req} end end context "Constructing arguments" do @@ -57,10 +58,22 @@ it 'applies scopes with one argument' do ScopeResource.expects(:one_arg).with(5).returns(ScopeResource) ScopeResource.add_scopes(one_arg: {id: 5}) end + it 'does not apply scopes with a blank argument' do + ScopeResource.expects(:one_arg).never + ScopeResource.add_scopes(one_arg: {id: ""}) + ScopeResource.add_scopes(one_arg: {id: nil}) + end + + it 'does not apply scopes when a parameter is missing' do + ScopeResource.expects(:two_args).never + ScopeResource.add_scopes(two_args: { page: 1 }) + ScopeResource.add_scopes(two_args: { per_page: 1 }) + end + it 'applies scopes with an array argument' do ScopeResource.expects(:one_array_arg).with([5]).returns(ScopeResource) ScopeResource.add_scopes(one_array_arg: {ids: [5]}) end @@ -91,8 +104,19 @@ it "applies scopes with mixed arg lists" do ScopeResource.expects(:mix_args).with(4,[5,6,7]).returns(ScopeResource) ScopeResource.add_scopes(mix_args: {id: 4, vararg: [5,6,7]}) end + + it 'parses dates if the parameters are correctly named' do + ScopeResource.expects(:date_scope) + .with(instance_of(Date), instance_of(Date)) + .returns(ScopeResource) + + ScopeResource.add_scopes({ + date_scope: { start_date: 'May 6, 2013', end_date: 'June 8, 2014' } + }) + end + end end \ No newline at end of file