mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
remove unused methods find_in_state, count_in_state, with_state_scope for MongoMapper
This commit is contained in:
parent
3970cc45b0
commit
68bf3fb474
3 changed files with 1 additions and 67 deletions
|
@ -23,3 +23,4 @@
|
|||
* check all tests
|
||||
* _ActiveRecord_
|
||||
* _Mongoid_
|
||||
* drop support for find_in_state, count_in_state, calculate_in_state, with_state_scope
|
||||
|
|
|
@ -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 <tt>state</tt> to the state column and persists it to the database
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Reference in a new issue