Skip to content

Commit

Permalink
play with initializing bitfields
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Oct 19, 2011
1 parent b3f8495 commit 2170dc5
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions spec/bitfields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ class ManyBitsUser < User
set_table_name 'users'
end

class InitializedUser < User
set_table_name 'users'
bitfield :bits, 1 => :seller, 2 => :insane, 4 => :stupid, :scopes => false

after_initialize do
self.seller = true
self.insane = false
end
end


describe Bitfields do
before do
User.delete_all
Expand Down Expand Up @@ -346,12 +357,30 @@ class ManyBitsUser < User
OverwrittenUser.bitfields.should == {:bits=>{:seller_inherited=>1}}
end

xit "knows inherited values when overwriting" do
OverwrittenUser.bitfield_column(:seller).should == :bits
it "knows inherited values when overwriting" do
pending do
OverwrittenUser.bitfield_column(:seller).should == :bits
end
end

xit "knows inherited values without overwriting" do
InheritedUser.bitfield_column(:seller).should == :bits
it "knows inherited values without overwriting" do
pending do
InheritedUser.bitfield_column(:seller).should == :bits
end
end
end

describe 'initializers' do
it "sets defaults" do
InitializedUser.new.seller.should == true
InitializedUser.new.insane.should == false
end

it "can overwrite defaults in new" do
pending do
InitializedUser.new(:seller => false).seller.should == false
InitializedUser.new(:insane => true).insane.should == true
end
end
end
end

0 comments on commit 2170dc5

Please sign in to comment.