Skip to content

Commit

Permalink
Fix extra fields
Browse files Browse the repository at this point in the history
  • Loading branch information
felixclack committed Feb 27, 2012
1 parent 81837a8 commit 962686c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
timeline (0.1.1)
timeline (0.1.4)
activemodel (~> 3.2)
activesupport (~> 3.2)
hashie
Expand Down
8 changes: 5 additions & 3 deletions lib/timeline/track.rb
Expand Up @@ -63,10 +63,12 @@ def add_activity_to_followers(activity_item, followers)
end

def add_extra_fields(extra_fields)
if extra_fields.any?
extra_fields.inject({}) do |sum, value|
sum[value.to_sym] = send value.to_sym
if !extra_fields.nil? and extra_fields.any?
extras = {}
extra_fields.each do |value|
extras[value] = send(value)
end
extras
else
{}
end
Expand Down
45 changes: 45 additions & 0 deletions spec/track_spec.rb
Expand Up @@ -30,6 +30,42 @@ def to_s
end
end

class Comment
extend ActiveModel::Callbacks

define_model_callbacks :create
attr_accessor :id, :creator_id

include Timeline::Track

track :new_comment, extra_fields: [:post_name, :post_id]

def initialize(options={})
@creator_id = options.delete :creator_id
end

def save
run_callbacks :create
true
end

def post_id
1
end

def post_name
"My Post"
end

def creator
User.find(creator_id)
end

def to_s
"Comment"
end
end

class User
include Timeline::Actor
attr_accessor :id, :to_param
Expand Down Expand Up @@ -78,4 +114,13 @@ def find user_id
follower.timeline.last.actor.id.should == 1
end
end

describe "with extra_fields" do
let(:comment) { Comment.new(creator_id: creator.id, id: 1) }

it "stores the extra fields in the timeline" do
comment.save
creator.timeline.first.should respond_to :post_id
end
end
end

0 comments on commit 962686c

Please sign in to comment.