Skip to content

Commit 962686c

Browse files
committed
Fix extra fields
1 parent 81837a8 commit 962686c

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
timeline (0.1.1)
4+
timeline (0.1.4)
55
activemodel (~> 3.2)
66
activesupport (~> 3.2)
77
hashie

lib/timeline/track.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ def add_activity_to_followers(activity_item, followers)
6363
end
6464

6565
def add_extra_fields(extra_fields)
66-
if extra_fields.any?
67-
extra_fields.inject({}) do |sum, value|
68-
sum[value.to_sym] = send value.to_sym
66+
if !extra_fields.nil? and extra_fields.any?
67+
extras = {}
68+
extra_fields.each do |value|
69+
extras[value] = send(value)
6970
end
71+
extras
7072
else
7173
{}
7274
end

spec/track_spec.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,42 @@ def to_s
3030
end
3131
end
3232

33+
class Comment
34+
extend ActiveModel::Callbacks
35+
36+
define_model_callbacks :create
37+
attr_accessor :id, :creator_id
38+
39+
include Timeline::Track
40+
41+
track :new_comment, extra_fields: [:post_name, :post_id]
42+
43+
def initialize(options={})
44+
@creator_id = options.delete :creator_id
45+
end
46+
47+
def save
48+
run_callbacks :create
49+
true
50+
end
51+
52+
def post_id
53+
1
54+
end
55+
56+
def post_name
57+
"My Post"
58+
end
59+
60+
def creator
61+
User.find(creator_id)
62+
end
63+
64+
def to_s
65+
"Comment"
66+
end
67+
end
68+
3369
class User
3470
include Timeline::Actor
3571
attr_accessor :id, :to_param
@@ -78,4 +114,13 @@ def find user_id
78114
follower.timeline.last.actor.id.should == 1
79115
end
80116
end
117+
118+
describe "with extra_fields" do
119+
let(:comment) { Comment.new(creator_id: creator.id, id: 1) }
120+
121+
it "stores the extra fields in the timeline" do
122+
comment.save
123+
creator.timeline.first.should respond_to :post_id
124+
end
125+
end
81126
end

0 commit comments

Comments
 (0)