Skip to content

Commit

Permalink
Add failing example for custom serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankur Sethi committed Apr 13, 2012
1 parent c73f4b9 commit c42aa4f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spec/lib/amoeba_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
new_post.widgets.map(&:id).each do |id|
old_post.widgets.map(&:id).include?(id).should_not be true
end
old_post.custom_things.length.should == 3
old_post.custom_things.select{ |ct| ct.value == [] }.length.should == 1
old_post.custom_things.select{ |ct| ct.value == [1,2]}.length.should == 1
old_post.custom_things.select{ |ct| ct.value == [78]}.length.should == 1
# }}}
# Author {{{
old_author = Author.find(1)
Expand Down
2 changes: 2 additions & 0 deletions spec/support/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,6 @@
necklace1.sections << jewelry
necklace1.sections << accessories
necklace1.save

p1.custom_things.create [{:value => [1,2]}, {:value => []},{ :value => [78]}]
# }}}
12 changes: 12 additions & 0 deletions spec/support/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Post < ActiveRecord::Base
has_many :categories, :through => :supercats
has_many :post_widgets
has_many :widgets, :through => :post_widgets
has_many :custom_things
has_and_belongs_to_many :tags
has_and_belongs_to_many :notes

Expand Down Expand Up @@ -73,6 +74,17 @@ class Post < ActiveRecord::Base

class CustomThing < ActiveRecord::Base
belongs_to :post
class ArrayPack
def load(str)
str.split(',')
end

def dump(int_array)
int_array.join(',')
end
end

serialize :value, ArrayPack.new
end

class Account < ActiveRecord::Base
Expand Down
1 change: 1 addition & 0 deletions spec/support/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
end

create_table :custom_things, :force => true do |t|
t.integer :post_id
t.string :value
t.timestamps
end
Expand Down

0 comments on commit c42aa4f

Please sign in to comment.