From 7eebc4c1a616625e02de62dce56fcde2c5164b42 Mon Sep 17 00:00:00 2001 From: Eugene Haisenka Date: Sun, 18 Sep 2016 17:06:10 +0300 Subject: [PATCH] Add tests for multiple named scopes --- spec/models/active_record/simple_new_dsl.rb | 4 ++-- spec/models/mongo_mapper/simple_mongo_mapper.rb | 4 ++-- spec/models/mongoid/simple_mongoid.rb | 4 ++-- .../persistence/active_record_persistence_multiple_spec.rb | 5 ++++- spec/unit/persistence/active_record_persistence_spec.rb | 5 ++++- .../persistence/mongo_mapper_persistence_multiple_spec.rb | 5 ++++- spec/unit/persistence/mongo_mapper_persistence_spec.rb | 5 ++++- spec/unit/persistence/mongoid_persistence_multiple_spec.rb | 5 ++++- spec/unit/persistence/mongoid_persistence_spec.rb | 5 ++++- 9 files changed, 30 insertions(+), 12 deletions(-) diff --git a/spec/models/active_record/simple_new_dsl.rb b/spec/models/active_record/simple_new_dsl.rb index 7e63f57..6563f55 100644 --- a/spec/models/active_record/simple_new_dsl.rb +++ b/spec/models/active_record/simple_new_dsl.rb @@ -2,7 +2,7 @@ class SimpleNewDsl < ActiveRecord::Base include AASM aasm :column => :status aasm do - state :unknown_scope + state :unknown_scope, :another_unknown_scope state :new end end @@ -11,7 +11,7 @@ class MultipleSimpleNewDsl < ActiveRecord::Base include AASM aasm :left, :column => :status aasm :left do - state :unknown_scope + state :unknown_scope, :another_unknown_scope state :new end end diff --git a/spec/models/mongo_mapper/simple_mongo_mapper.rb b/spec/models/mongo_mapper/simple_mongo_mapper.rb index b8bdc56..7d11437 100644 --- a/spec/models/mongo_mapper/simple_mongo_mapper.rb +++ b/spec/models/mongo_mapper/simple_mongo_mapper.rb @@ -5,7 +5,7 @@ class SimpleMongoMapper key :status, String aasm column: :status do - state :unknown_scope + state :unknown_scope, :another_unknown_scope state :next end end @@ -17,7 +17,7 @@ class SimpleMongoMapperMultiple key :status, String aasm :left, column: :status do - state :unknown_scope + state :unknown_scope, :another_unknown_scope state :next end end diff --git a/spec/models/mongoid/simple_mongoid.rb b/spec/models/mongoid/simple_mongoid.rb index 996dec2..8c0d10d 100644 --- a/spec/models/mongoid/simple_mongoid.rb +++ b/spec/models/mongoid/simple_mongoid.rb @@ -5,7 +5,7 @@ class SimpleMongoid field :status, :type => String aasm column: :status do - state :unknown_scope + state :unknown_scope, :another_unknown_scope state :new end end @@ -17,7 +17,7 @@ class SimpleMongoidMultiple field :status, :type => String aasm :left, column: :status do - state :unknown_scope + state :unknown_scope, :another_unknown_scope state :new end end diff --git a/spec/unit/persistence/active_record_persistence_multiple_spec.rb b/spec/unit/persistence/active_record_persistence_multiple_spec.rb index ce1a335..3076bbc 100644 --- a/spec/unit/persistence/active_record_persistence_multiple_spec.rb +++ b/spec/unit/persistence/active_record_persistence_multiple_spec.rb @@ -296,9 +296,12 @@ end describe "named scopes with the new DSL" do context "Does not already respond_to? the scope name" do - it "should add a scope" do + it "should add a scope for each state" do expect(MultipleSimpleNewDsl).to respond_to(:unknown_scope) + expect(MultipleSimpleNewDsl).to respond_to(:another_unknown_scope) + expect(MultipleSimpleNewDsl.unknown_scope.is_a?(ActiveRecord::Relation)).to be_truthy + expect(MultipleSimpleNewDsl.another_unknown_scope.is_a?(ActiveRecord::Relation)).to be_truthy end end diff --git a/spec/unit/persistence/active_record_persistence_spec.rb b/spec/unit/persistence/active_record_persistence_spec.rb index d673231..2774698 100644 --- a/spec/unit/persistence/active_record_persistence_spec.rb +++ b/spec/unit/persistence/active_record_persistence_spec.rb @@ -296,9 +296,12 @@ end describe "named scopes with the new DSL" do context "Does not already respond_to? the scope name" do - it "should add a scope" do + it "should add a scope for each state" do expect(SimpleNewDsl).to respond_to(:unknown_scope) + expect(SimpleNewDsl).to respond_to(:another_unknown_scope) + expect(SimpleNewDsl.unknown_scope.is_a?(ActiveRecord::Relation)).to be_truthy + expect(SimpleNewDsl.another_unknown_scope.is_a?(ActiveRecord::Relation)).to be_truthy end end diff --git a/spec/unit/persistence/mongo_mapper_persistence_multiple_spec.rb b/spec/unit/persistence/mongo_mapper_persistence_multiple_spec.rb index 7e096d3..d212111 100644 --- a/spec/unit/persistence/mongo_mapper_persistence_multiple_spec.rb +++ b/spec/unit/persistence/mongo_mapper_persistence_multiple_spec.rb @@ -28,9 +28,12 @@ describe 'mongo_mapper' do describe "named scopes with the old DSL" do context "Does not already respond_to? the scope name" do - it "should add a scope" do + it "should add a scope for each state" do expect(SimpleMongoMapperMultiple).to respond_to(:unknown_scope) + expect(SimpleMongoMapperMultiple).to respond_to(:another_unknown_scope) + expect(SimpleMongoMapperMultiple.unknown_scope.class).to eq(MongoMapper::Plugins::Querying::DecoratedPluckyQuery) + expect(SimpleMongoMapperMultiple.another_unknown_scope.class).to eq(MongoMapper::Plugins::Querying::DecoratedPluckyQuery) #expect(SimpleMongoMapperMultiple.unknown_scope.is_a?(ActiveRecord::Relation)).to be_truthy end end diff --git a/spec/unit/persistence/mongo_mapper_persistence_spec.rb b/spec/unit/persistence/mongo_mapper_persistence_spec.rb index acaf772..f954b16 100644 --- a/spec/unit/persistence/mongo_mapper_persistence_spec.rb +++ b/spec/unit/persistence/mongo_mapper_persistence_spec.rb @@ -28,9 +28,12 @@ describe 'mongo_mapper' do describe "named scopes with the old DSL" do context "Does not already respond_to? the scope name" do - it "should add a scope" do + it "should add a scope for each state" do expect(SimpleMongoMapper).to respond_to(:unknown_scope) + expect(SimpleMongoMapper).to respond_to(:another_unknown_scope) + expect(SimpleMongoMapper.unknown_scope.class).to eq(MongoMapper::Plugins::Querying::DecoratedPluckyQuery) + expect(SimpleMongoMapper.another_unknown_scope.class).to eq(MongoMapper::Plugins::Querying::DecoratedPluckyQuery) #expect(SimpleMongoMapper.unknown_scope.is_a?(ActiveRecord::Relation)).to be_truthy end end diff --git a/spec/unit/persistence/mongoid_persistence_multiple_spec.rb b/spec/unit/persistence/mongoid_persistence_multiple_spec.rb index f1c7cec..ec837aa 100644 --- a/spec/unit/persistence/mongoid_persistence_multiple_spec.rb +++ b/spec/unit/persistence/mongoid_persistence_multiple_spec.rb @@ -24,9 +24,12 @@ describe 'mongoid' do describe "named scopes with the old DSL" do context "Does not already respond_to? the scope name" do - it "should add a scope" do + it "should add a scope for each state" do expect(SimpleMongoidMultiple).to respond_to(:unknown_scope) + expect(SimpleMongoidMultiple).to respond_to(:another_unknown_scope) + expect(SimpleMongoidMultiple.unknown_scope.class).to eq(Mongoid::Criteria) + expect(SimpleMongoidMultiple.another_unknown_scope.class).to eq(Mongoid::Criteria) end end diff --git a/spec/unit/persistence/mongoid_persistence_spec.rb b/spec/unit/persistence/mongoid_persistence_spec.rb index d51810e..d65d9c0 100644 --- a/spec/unit/persistence/mongoid_persistence_spec.rb +++ b/spec/unit/persistence/mongoid_persistence_spec.rb @@ -24,9 +24,12 @@ describe 'mongoid' do describe "named scopes with the old DSL" do context "Does not already respond_to? the scope name" do - it "should add a scope" do + it "should add a scope for each state" do expect(SimpleMongoid).to respond_to(:unknown_scope) + expect(SimpleMongoid).to respond_to(:another_unknown_scope) + expect(SimpleMongoid.unknown_scope.class).to eq(Mongoid::Criteria) + expect(SimpleMongoid.another_unknown_scope.class).to eq(Mongoid::Criteria) end end