From 68bf3fb4742a009d39d552e8d12bd7080e28e9e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Bo=CC=88ttger?= Date: Sat, 11 Jul 2015 00:19:59 +1200 Subject: [PATCH] remove unused methods find_in_state, count_in_state, with_state_scope for MongoMapper --- PLANNED_CHANGES.md | 1 + .../persistence/mongo_mapper_persistence.rb | 21 --------- .../mongo_mapper_persistance_spec.rb | 46 ------------------- 3 files changed, 1 insertion(+), 67 deletions(-) diff --git a/PLANNED_CHANGES.md b/PLANNED_CHANGES.md index 645889f..ca433e1 100644 --- a/PLANNED_CHANGES.md +++ b/PLANNED_CHANGES.md @@ -23,3 +23,4 @@ * check all tests * _ActiveRecord_ * _Mongoid_ + * drop support for find_in_state, count_in_state, calculate_in_state, with_state_scope diff --git a/lib/aasm/persistence/mongo_mapper_persistence.rb b/lib/aasm/persistence/mongo_mapper_persistence.rb index 871566f..2dc41d7 100644 --- a/lib/aasm/persistence/mongo_mapper_persistence.rb +++ b/lib/aasm/persistence/mongo_mapper_persistence.rb @@ -32,7 +32,6 @@ module AASM # def self.included(base) base.send(:include, AASM::Persistence::Base) - base.extend AASM::Persistence::MongoMapperPersistence::ClassMethods base.send(:include, AASM::Persistence::MongoMapperPersistence::InstanceMethods) base.before_create :aasm_ensure_initial_state @@ -41,26 +40,6 @@ module AASM base.validate :aasm_validate_states end - module ClassMethods - - def find_in_state(number, state, *args) - with_state_scope(state).find!(number, *args) - end - - def count_in_state(state, *args) - with_state_scope(state).count(*args) - end - - def calculate_in_state(state, *args) - with_state_scope(state).calculate(*args) - end - - protected - def with_state_scope(state) - where(aasm.attribute_name.to_sym => state.to_s) - end - end - module InstanceMethods # Writes state to the state column and persists it to the database diff --git a/spec/unit/persistence/mongo_mapper_persistance_spec.rb b/spec/unit/persistence/mongo_mapper_persistance_spec.rb index d7ce651..e33a2d2 100644 --- a/spec/unit/persistence/mongo_mapper_persistance_spec.rb +++ b/spec/unit/persistence/mongo_mapper_persistance_spec.rb @@ -64,52 +64,6 @@ describe 'mongo_mapper' do end - describe "#find_in_state" do - - let!(:model) { SimpleNewDslMongoMapper.create!(:status => :unknown_scope) } - let!(:model_id) { model._id } - - it "should respond to method" do - expect(SimpleNewDslMongoMapper).to respond_to(:find_in_state) - end - - it "should find the model when given the correct scope and model id" do - expect(SimpleNewDslMongoMapper.find_in_state(model_id, 'unknown_scope').class).to eq(SimpleNewDslMongoMapper) - expect(SimpleNewDslMongoMapper.find_in_state(model_id, 'unknown_scope')).to eq(model) - end - - it "should raise DocumentNotFound error when given incorrect scope" do - expect {SimpleNewDslMongoMapper.find_in_state(model_id, 'next')}.to raise_error MongoMapper::DocumentNotFound - end - - it "should raise DocumentNotFound error when given incorrect model id" do - expect {SimpleNewDslMongoMapper.find_in_state('bad_id', 'unknown_scope')}.to raise_error MongoMapper::DocumentNotFound - end - - end - - describe "#count_in_state" do - - before do - 3.times { SimpleNewDslMongoMapper.create!(:status => :unknown_scope) } - end - - it "should respond to method" do - expect(SimpleNewDslMongoMapper).to respond_to(:count_in_state) - end - - it "should return n for a scope with n records persisted" do - expect(SimpleNewDslMongoMapper.count_in_state('unknown_scope').class).to eq(Fixnum) - expect(SimpleNewDslMongoMapper.count_in_state('unknown_scope')).to eq(3) - end - - it "should return zero for a scope without records persisted" do - expect(SimpleNewDslMongoMapper.count_in_state('next').class).to eq(Fixnum) - expect(SimpleNewDslMongoMapper.count_in_state('next')).to eq(0) - end - - end - describe "instance methods" do let(:simple) {SimpleNewDslMongoMapper.new}