Skip to content

Commit

Permalink
Send to known email address
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmike committed May 31, 2014
1 parent 9b2c07e commit 2b703f3
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
15 changes: 9 additions & 6 deletions app/views/distributions/recipient_suggestions.html.haml
Expand Up @@ -11,14 +11,17 @@
%td= fields.text_field :coin_amount, hide_label: true
%a.btn.btn-default.add-recipient-button{href: "#", data: {recipients: recipients}}= "#{user.nickname} (GitHub user)"
- if params[:text] =~ Devise::email_regexp
- recipient_name = "#{params[:text]} (unknown email address)"
- user = User.where(email: params[:text]).first_or_initialize
%li
- recipients = capture_haml do
= f.fields_for :tips, Tip.new(user: User.new(email: params[:text])), child_index: rand(1<<160) do |fields|
= f.fields_for :tips, Tip.new(user: user), child_index: rand(1<<160) do |fields|
%tr
%td
= fields.fields_for :user do |user_fields|
= user_fields.hidden_field :email
= recipient_name
- if user.new_record?
= fields.fields_for :user do |user_fields|
= user_fields.hidden_field :email
- else
= fields.hidden_field :user_id
= user.recipient_label
%td= fields.text_field :coin_amount, hide_label: true
%a.btn.btn-default.add-recipient-button{href: "#", data: {recipients: recipients}}= recipient_name
%a.btn.btn-default.add-recipient-button{href: "#", data: {recipients: recipients}}= user.recipient_label
60 changes: 60 additions & 0 deletions features/distribution.feature
Expand Up @@ -228,3 +228,63 @@ Feature: Fundraisers can distribute funds
| mi9SLroAgc8eUNuLwnZmdyqWdShbNtvr3n | 5.0 |
And the project balance should be "480"

@javascript
Scenario: Send to a known email address
Given an user with email "bob@example.com"

Given a project managed by "alice"
And our fee is "0"
And a deposit of "500"

Given I'm logged in as "alice"
And I go to the project page
And I click on "New distribution"
And I type "bob@example.com" in the recipient field
And I select the recipient "bob@example.com"
And I fill the amount to "bob@example.com" with "10"
And I click on "Save"

Then I should see these distribution lines:
| recipient | address | amount | percentage |
| bob@example.com | | 10 | 100.0 |
And I should see "The transaction cannot be sent because some addresses are missing"

And no email should have been sent

When the tipper is started
Then no coins should have been sent
And no email should have been sent

When I click on "Send email request to provide an address"
Then I should see these distribution lines:
| recipient | address | amount | percentage |
| bob@example.com | | 10 | 100.0 |

And an email should have been sent to "bob@example.com"
And the email should include "alice"
And the email should include a link to the last distribution
When I visit the link to set my password and address from the email
And I fill "Password" with "password"
And I fill "Password confirmation" with "password"
And I fill "Peercoin address" with "mubmzLrtTgDE2WrHkiwSFKuTh2VTSXboYK"
And I click on "Save"

Then I should see "Information saved"
And the user with email "bob@example.com" should have "password" as password
And the user with email "bob@example.com" should have "mubmzLrtTgDE2WrHkiwSFKuTh2VTSXboYK" as peercoin address

When I log out
And I log in as "alice"
And I go to the project page
And I click on the last distribution
Then I should see these distribution lines:
| recipient | address | amount | percentage |
| bob@example.com | mubmzLrtTgDE2WrHkiwSFKuTh2VTSXboYK | 10 | 100.0 |

When I click on "Send the transaction"
Then I should see "Transaction sent"
And these amounts should have been sent from the account of the project:
| address | amount |
| mubmzLrtTgDE2WrHkiwSFKuTh2VTSXboYK | 10.0 |
And the project balance should be "490.00"

4 changes: 4 additions & 0 deletions features/step_definitions/distribution.rb
Expand Up @@ -7,6 +7,10 @@
create(:user, email: "#{arg1}@example.com", nickname: arg1, bitcoin_address: nil)
end

Given(/^an user with email "(.*?)"$/) do |arg1|
create(:user, email: arg1, nickname: nil, bitcoin_address: nil)
end

Given(/^I type "(.*?)" in the recipient field$/) do |arg1|
fill_in "add-recipients-input", with: arg1
end
Expand Down

0 comments on commit 2b703f3

Please sign in to comment.