Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/innsights/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize(name, options=nil)
options ||= {}
@name = name
@user_object = options[:user]
@group_object = fetch_group(options[:group])
@group_object = fetch_group(options)
@created_at = options[:created_at] || Time.now
@metrics = options[:measure] || {}
end
Expand Down Expand Up @@ -85,8 +85,8 @@ def user

private

def fetch_group(group_object)
return group_object if group_object.present?
def fetch_group(options)
return options[:group] if options.has_key? :group
return user.group if user.present?
nil
end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_spec/integration/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
describe "#report" do
it 'Can report a manual action' do
Innsights.client.should_receive(:report)
Innsights.report('Mention', dude).run
Innsights.report('Mention', user: dude).run
end
it 'Can create a custom create action' do
Dude.after_create lambda {|record| Innsights.report('Mention').run }
Expand Down
22 changes: 22 additions & 0 deletions spec/innsights/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ def some_method;end;
r = Innsights::Report.new("Mention", group: company)
r.group.object.should == company
end
it 'Takes the user group as default' do
company = Company.new
user.company = company
Innsights.group_call = :company
r = Innsights::Report.new("Mention", user: user)
r.group.object.should == company
end
it 'Can override the group if given' do
company = Company.new name: "Original"
user.company = company
company_override = Company.new name: "Override"
Innsights.group_call = :company
r = Innsights::Report.new("Mention", user: user, group: company_override)
r.group.object.should == company_override
end
it 'Can override the group with nil' do
company = Company.new name: "Original"
user.company = company
Innsights.group_call = :company
r = Innsights::Report.new("Mention", user: user, group: nil)
r.group.should == nil
end
it 'Can add a created_at' do
time = Time.now
r = Innsights::Report.new("Mention", created_at: time)
Expand Down