Skip to content

Commit

Permalink
Fix bug in member activity rule that counts a 'subscribed' event on a…
Browse files Browse the repository at this point in the history
…n action page as 'action_taken'

Remove JoinModule from this list cutting filter b/c we don't care how many time members have joined. We might care when they joined, which the join_date_rule satisfies.
  • Loading branch information
johnam committed Sep 15, 2014
1 parent 24f6330 commit 0ebe8b9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/models/list_cutter/member_activity_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class MemberActivityRule < ActivityCountRule
'Petition' => PetitionModule.name,
'Donation' => DonationModule.name,
'Email A Target' => EmailTargetsModule.name,
'Join' => JoinModule.name
}

fields :activity_count_operator, :activity_count, :activity_module_types, :activity_since_date
Expand Down Expand Up @@ -34,6 +33,7 @@ def to_sql
SELECT uae.user_id, COUNT(uae.user_id) AS activity_count
FROM user_activity_events uae
WHERE uae.content_module_type IN (?)
AND uae.activity = 'action_taken'
AND uae.created_at >= ?
AND uae.movement_id = ?
GROUP BY uae.user_id
Expand Down
67 changes: 49 additions & 18 deletions spec/models/list_cutter/member_activity_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,9 @@
create(:activity, user: @user4, content_module: create(:email_targets_module))
create(:email_sent_activity, user: @user5)
create(:email_sent_activity, user: @user6)
create(:activity, user: @user1, content_module: create(:join_module))
create(:activity, user: @user2, content_module: create(:donation_module))
create(:activity, user: @user3, content_module: create(:petition_module))
create(:activity, user: @user4, content_module: create(:join_module))
create(:activity, user: @user1, content_module: create(:email_targets_module))
create(:activity, user: @user2, content_module: create(:join_module))

options = {activity_since_date: Date.yesterday.strftime("%m/%d/%Y")}
@verifier = Proc.new do |range_operator, activity_count, expected_users, activity_module_types|
Expand All @@ -61,15 +58,16 @@

it "should return users based on combinations of actions taken" do
@verifier.call("equal_to", 2, [@user2], ['DonationModule', 'EmailTargetsModule'])
@verifier.call("more_than", 1, [@user1, @user2, @user3, @user4], ['DonationModule', 'EmailTargetsModule', 'JoinModule', 'PetitionModule'])
@verifier.call("equal_to", 2, [@user3, @user4], ['DonationModule', 'EmailTargetsModule', 'JoinModule', 'PetitionModule'])
@verifier.call("more_than", 3, [], ['DonationModule', 'EmailTargetsModule', 'JoinModule', 'PetitionModule'])
@verifier.call("more_than", 1, [@user1, @user2, @user3, @user4], ['DonationModule', 'EmailTargetsModule', 'JoinModule', 'PetitionModule'])
@verifier.call("less_than", 1, [@user5, @user6], ['DonationModule', 'EmailTargetsModule', 'JoinModule', 'PetitionModule'])
@verifier.call("more_than", 1, [@user1, @user2, @user3], ['DonationModule', 'EmailTargetsModule', 'PetitionModule'])
@verifier.call("equal_to", 2, [@user1, @user2, @user3], ['DonationModule', 'EmailTargetsModule', 'PetitionModule'])
@verifier.call("more_than", 3, [], ['DonationModule', 'EmailTargetsModule', 'PetitionModule'])
@verifier.call("more_than", 0, [@user1, @user2, @user3, @user4], ['DonationModule', 'EmailTargetsModule', 'PetitionModule'])
@verifier.call("less_than", 1, [@user5, @user6], ['DonationModule', 'EmailTargetsModule', 'PetitionModule'])
end
end

describe "filter on single module type" do
before(:each) do
before do
@movement = create(:movement)
@user1 = create(:user, movement: @movement)
@user2 = create(:user, movement: @movement)
Expand All @@ -84,12 +82,9 @@
create(:activity, user: @user4, content_module: create(:email_targets_module))
create(:email_sent_activity, user: @user5)
create(:email_sent_activity, user: @user6)
create(:activity, user: @user1, content_module: create(:join_module))
create(:activity, user: @user2, content_module: create(:donation_module))
create(:activity, user: @user3, content_module: create(:petition_module))
create(:activity, user: @user4, content_module: create(:join_module))
create(:activity, user: @user1, content_module: create(:email_targets_module))
create(:activity, user: @user2, content_module: create(:join_module))

options = {activity_since_date: Date.yesterday.strftime("%m/%d/%Y")}
@verifier = Proc.new do |range_operator, activity_count, expected_users, activity_module_types|
Expand All @@ -103,12 +98,6 @@
end

end
it "should return users filtered on the magnitude to members joined" do
@verifier.call("equal_to", 2, [], ['JoinModule'])
@verifier.call("more_than", 0, [@user1, @user4, @user2], ['JoinModule'])
@verifier.call("equal_to", 0, [@user3, @user5, @user6], ['JoinModule'])
@verifier.call("less_than", 2, [@user1, @user2, @user3, @user4, @user5, @user6], ['JoinModule'])
end

it "should return users filtered on the magnitude of number of donations made" do
@verifier.call("equal_to", 2, [@user2], ['DonationModule'])
Expand All @@ -134,6 +123,48 @@
@verifier.call("less_than", 3, [@user1, @user3, @user4, @user5, @user6, @user2], ['EmailTargetsModule'])
end
end

describe "distinguish between 'subscribed' and 'action_taken' activity for members that join through: " do

before do
@verify = Proc.new do |content_module_type|
movement = create(:movement)
module1 = create(content_module_type.underscore.to_sym)
module2 = create(content_module_type.underscore.to_sym)
user1 = create(:user, movement: movement)
user2 = create(:user, movement: movement)

create(:activity, user: user1, content_module: module1, movement: movement)
create(:subscribed_activity, user: user1, content_module: module1, movement: movement)
create(:activity, user: user2, content_module: module1, movement: movement)
create(:activity, user: user2, content_module: module2, movement: movement)

options = {activity_since_date: Date.yesterday.strftime("%m/%d/%Y")}
actual_users = ListCutter::MemberActivityRule.new(options.merge(
activity_count_operator: 'more_than',
activity_count: 1,
activity_module_types: [content_module_type],
movement: movement
)).to_relation.all

actual_users.should == [user2]
end
end

it 'petition' do
@verify.call('PetitionModule')
end

it 'donation' do
@verify.call('DonationModule')
end

it 'email targets' do
@verify.call('EmailTargetsModule')
end

end

end

describe "to_human_sql" do
Expand Down

0 comments on commit 0ebe8b9

Please sign in to comment.