Permalink
Browse files

Fix propagating options to the child classes when inheriting models.

  • Loading branch information...
1 parent 497f589 commit bbf02eb4f45985f8c33bab3d470a677375a3e663 @pk committed Feb 16, 2010
Showing with 26 additions and 0 deletions.
  1. +8 −0 lib/sequel_sluggable.rb
  2. +18 −0 spec/sequel_sluggable_spec.rb
@@ -31,6 +31,14 @@ def find_by_slug(value)
self[@sluggable_options[:target] => value.chomp]
end
+ # Propagate settings to the child classes
+ #
+ # @param [Class] Child class
+ def inherited(klass)
+ super
+ klass.sluggable_options = self.sluggable_options.dup
+ end
+
# Set the plugin options
#
# Options:
@@ -62,6 +62,24 @@ class Item < Sequel::Model; end
class Item < Sequel::Model; end
lambda { Item.plugin :sluggable, :source => :name, :sluggator => 'xy' }.should raise_error(ArgumentError, "If you provide :sluggator it must be Symbol or callable.")
end
+
+ it "should preserve options in sub classes" do
+ class SubItem < Item; end
+ SubItem.sluggable_options.should_not be_nil
+ end
+
+ it "should allow to change options for sub class" do
+ class SubItem < Item; end
+ SubItem.plugin :sluggable, :source => :test
+ SubItem.sluggable_options[:source].should eql :test
+ end
+
+ it "should not mess with parent settings when inherited" do
+ class SubItem < Item; end
+ SubItem.sluggable_options[:source] = :test
+ SubItem.sluggable_options[:source].should eql :test
+ Item.sluggable_options[:source].should eql :name
+ end
end
describe "::find_by_pk_or_slug" do

0 comments on commit bbf02eb

Please sign in to comment.