Skip to content
This repository has been archived by the owner on Jul 8, 2018. It is now read-only.

Commit

Permalink
Avoid to affect the parent when adding orderable config in inherited …
Browse files Browse the repository at this point in the history
…class
  • Loading branch information
oMiyakeJTakuma committed Jun 25, 2014
1 parent 4c74c73 commit 38a3577
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/mongoid/orderable/orderable_class.rb
Expand Up @@ -34,12 +34,12 @@ def add_db_index

def save_configuration
klass.orderable_configurations ||= {}
klass.orderable_configurations[column_name] = configuration
klass.orderable_configurations = klass.orderable_configurations.merge(column_name => configuration)
end

def add_callbacks
klass.add_orderable_callbacks
end
end
end
end
end
11 changes: 11 additions & 0 deletions spec/mongoid/orderable_spec.rb
Expand Up @@ -689,6 +689,17 @@ def positions
end.to change(first_apple, :position).from(top_pos).to bottom_pos
end
end

describe 'add orderable configurations in inherited class' do
it 'does not affect the orderable configurations of parent class and sibling class' do
class Apple
orderable :column => :serial
end
expect(Fruit.orderable_configurations).not_to eq Apple.orderable_configurations
expect(Orange.orderable_configurations).not_to eq Apple.orderable_configurations
expect(Fruit.orderable_configurations).to eq Orange.orderable_configurations
end
end
end

describe ForeignKeyDiffersOrderable do
Expand Down

0 comments on commit 38a3577

Please sign in to comment.