Skip to content
Permalink
Browse files

add test case whit mixins

  • Loading branch information...
dubadub committed Jun 6, 2019
1 parent 3eb9d6a commit 9d688cdc65cb71b68e2ff71aa707bf6fb1a327e0
Showing with 36 additions and 1 deletion.
  1. +1 −1 lib/filtered/base.rb
  2. +35 −0 spec/filtered_spec.rb
@@ -221,7 +221,7 @@ def to_hash
end

def inspect
inspection = fields.collect { |name, value| "#{name}: #{value.inspect}" }.compact.join(", ")
inspection = entitled_fields.collect { |name, value| "#{name}: #{value.inspect}" }.compact.join(", ")

"#<#{self.class} #{inspection}>"
end
@@ -41,6 +41,41 @@ class Filter2 < FilterBase
expect(filter_two).to have_filter_value(reason: "because", base_status: "pending", base_reason: "N/A")
end

it "doesn't clash with other class with common ancestor" do
module FilterMixin1
def self.included(base)
base.field :status, default: "hello"
end
end

module FilterMixin2
def self.included(base)
base.field :reason, default: "because"
end
end

class FilterBase < Filtered::Base
field :base_status, default: "pending"
field :base_reason, default: "N/A"
end

class Filter1 < FilterBase
include FilterMixin1
end

class Filter2 < FilterBase
include FilterMixin2

field :filter_two_own_field, default: "today"
end

filter_one = Filter1.new
filter_two = Filter2.new

expect(filter_one).to have_filter_value(status: "hello", base_status: "pending", base_reason: "N/A")
expect(filter_two).to have_filter_value(reason: "because", base_status: "pending", base_reason: "N/A", filter_two_own_field: "today")
end

it "blows up when setting field which is not defined" do
class MyFilter < Filtered::Base
field :status

0 comments on commit 9d688cd

Please sign in to comment.
You can’t perform that action at this time.