Skip to content

Commit d28794d

Browse files
committed
Developers must opt-in to receive tips.
1 parent 89daf60 commit d28794d

6 files changed

Lines changed: 53 additions & 13 deletions

File tree

app/models/project.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ def tip_commits
117117
def tip_for commit
118118
if (next_tip_amount > 0) && !Tip.exists?(commit: commit.sha)
119119

120-
user = User.find_or_create_with_commit commit
120+
user = User.find_by_commit(commit)
121+
return unless user
122+
121123
user.update(nickname: commit.author.login) if commit.author.try(:login)
122124

123125
if hold_tips

app/models/user.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,11 @@ def self.create_with_omniauth!(auth_info)
5050
end
5151
end
5252

53-
def self.find_or_create_with_commit commit
54-
author = commit.commit.author
53+
def self.find_by_commit(commit)
54+
email = commit.commit.author.email
5555
nickname = commit.author.try(:login)
56-
user = find_by(nickname: nickname) if nickname
57-
user || where(email: author.email).first_or_create do |user|
58-
user.email = author.email
59-
user.password = Devise.friendly_token.first(Devise.password_length.min)
60-
user.name = author.name
61-
user.nickname = nickname
62-
user.skip_confirmation!
63-
end
56+
57+
find_by(email: email) || find_by(nickname: nickname)
6458
end
6559

6660
private
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Feature: Developers must opt-in to create an account and receive tips
2+
Background:
3+
Given a project "my-project"
4+
And our fee is "0"
5+
And a deposit of "500"
6+
And the last known commit is "COMMIT1"
7+
8+
Scenario: Tipping a opted-in developer
9+
And a user "yugo" has opted-in
10+
And a new commit "COMMIT2" with parent "COMMIT1"
11+
And the author of commit "COMMIT2" is "yugo"
12+
And the message of commit "COMMIT2" is "Tiny change"
13+
When the new commits are read
14+
Then there should be a tip of "5" for commit "COMMIT2"
15+
And there should be 1 email sent
16+
17+
Scenario: Tipping a developer that has not opted-in
18+
And a new commit "COMMIT2" with parent "COMMIT1"
19+
And the author of commit "COMMIT2" is "yugo"
20+
And the message of commit "COMMIT2" is "Tiny change"
21+
When the new commits are read
22+
Then there should be no tip for commit "COMMIT2"
23+
And there should be 0 email sent

features/step_definitions/common.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
@project = Project.create!(full_name: "example/#{arg1}", github_id: Digest::SHA1.hexdigest(arg1), bitcoin_address: 'mq4NtnmQoQoPfNWEPbhSvxvncgtGo6L8WY')
3030
end
3131

32+
Given(/^a user "(.*?)" has opted\-in$/) do |arg1|
33+
User.find_or_create_by!(nickname: arg1) do |user|
34+
user.nickname = arg1
35+
user.password = "password"
36+
user.email = "#{arg1.parameterize}@example.com"
37+
user.skip_confirmation!
38+
end
39+
end
40+
3241
Given(/^a deposit of "(.*?)"$/) do |arg1|
3342
Deposit.create!(project: @project, amount: arg1.to_d * 1e8, confirmations: 2)
3443
end
@@ -48,6 +57,14 @@ def add_new_commit(id, params = {})
4857
},
4958
},
5059
}
60+
61+
User.find_or_create_by(email: "anonymous@example.com") do |user|
62+
user.nickname = "anonymous"
63+
user.email = "anonymous@example.com"
64+
user.password = "password"
65+
user.skip_confirmation!
66+
end
67+
5168
@new_commits[id] = defaults.deep_merge(params)
5269
end
5370

features/step_definitions/web.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
Given(/^I'm logged in as "(.*?)"$/) do |arg1|
2+
email = "#{arg1.parameterize}@example.com"
3+
24
OmniAuth.config.test_mode = true
35
OmniAuth.config.mock_auth[:github] = {
46
"info" => {
57
"nickname" => arg1,
6-
"primary_email" => "#{arg1.gsub(/\s+/,'')}@example.com",
7-
"verified_emails" => [],
8+
"primary_email" => email,
9+
"verified_emails" => [email],
810
},
911
}.to_ostruct
1012
visit root_path

features/tip_modifier_interface.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Feature: A project collaborator can change the tips of commits
22
Background:
33
Given a project "a"
4+
And a user "yugo" has opted-in
5+
And a user "gaal" has opted-in
46
And the project collaborators are:
57
| seldon |
68
| daneel |

0 commit comments

Comments
 (0)