Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #50 from chak/failing_test
Browse files Browse the repository at this point in the history
create a test that exhibits failing behavior on subclasses
  • Loading branch information
joelmoss committed Nov 3, 2013
2 parents f194d30 + 5fffab7 commit 0b905e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/bitmask_attributes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,18 @@ def assert_stored(record, *values)
context_with_classes 'Campaign without null attributes', CampaignWithoutNull, CompanyWithoutNull
context_with_classes 'SubCampaign with null attributes', SubCampaignWithNull, CompanyWithNull
context_with_classes 'SubCampaign without null attributes', SubCampaignWithoutNull, CompanyWithoutNull

should "allow subclasses to have different values for bitmask than parent" do
a = CampaignWithNull.new
b = SubCampaignWithNull.new
a.different_per_class = [:set_for_parent]
b.different_per_class = [:set_for_sub]
a.save!
b.save!
a.reload
b.reload
assert_equal a.different_per_class, [:set_for_parent]
assert_equal b.different_per_class, [:set_for_sub]
end

end
4 changes: 4 additions & 0 deletions test/support/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
create_table :campaign_with_nulls do |t|
t.integer :company_id
t.integer :medium, :allow_zero, :misc, :Legacy
t.integer :different_per_class
t.string :type # STI
end
create_table :company_with_nulls do |t|
Expand All @@ -10,6 +11,7 @@
create_table :campaign_without_nulls do |t|
t.integer :company_id
t.integer :medium, :allow_zero, :misc, :Legacy, :null => false, :default => 0
t.integer :different_per_class
t.string :type # STI
end
create_table :company_without_nulls do |t|
Expand All @@ -30,6 +32,7 @@ class CampaignWithNull < ActiveRecord::Base
belongs_to :company,:class_name => 'CompanyWithNull'
bitmask :medium, :as => [:web, :print, :email, :phone]
bitmask :allow_zero, :as => [:one, :two, :three], :zero_value => :none
bitmask :different_per_class, :as => [:set_for_parent]
bitmask :misc, :as => %w(some useless values) do
def worked?
true
Expand All @@ -39,6 +42,7 @@ def worked?
end

class SubCampaignWithNull < CampaignWithNull
bitmask :different_per_class, :as => [:set_for_sub]
end

class CompanyWithoutNull < ActiveRecord::Base
Expand Down

0 comments on commit 0b905e1

Please sign in to comment.