Skip to content

Commit

Permalink
Can add comment to distribution line
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmike committed Jun 1, 2014
1 parent fa700dc commit a4f2b16
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/distributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def send_transaction
private

def distribution_params
params.require(:distribution).permit(tips_attributes: [:id, :coin_amount, :user_id, {user_attributes: [:email]}])
params.require(:distribution).permit(tips_attributes: [:id, :coin_amount, :user_id, :comment, {user_attributes: [:email]}])
end

def finalize_distribution
Expand Down
2 changes: 2 additions & 0 deletions app/views/distributions/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
%table.table
%thead
%th Recipient
%th Comment
%th Amount
%tbody#recipients
= f.fields_for :tips do |fields|
Expand All @@ -13,6 +14,7 @@
= fields.hidden_field :id
= fields.hidden_field :user_id
= link_to user.recipient_label, user
%td= fields.text_field :comment, hide_label: true
%td= fields.text_field :coin_amount, hide_label: true
.form-group
%label{for: "add-recipients-input"} Add recipient(s)
Expand Down
2 changes: 2 additions & 0 deletions app/views/distributions/recipient_suggestions.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- else
= fields.hidden_field :user_id
= link_to user.recipient_label, user
%td= fields.text_field :comment, hide_label: true
%td= fields.text_field :coin_amount, hide_label: true
- suggestions << [user.recipient_label, recipients]
- User.where('nickname LIKE ?', "%#{params[:text]}%").each do |user|
Expand All @@ -22,6 +23,7 @@
%td
= fields.hidden_field :user_id
= link_to user.recipient_label, user
%td= fields.text_field :comment, hide_label: true
%td= fields.text_field :coin_amount, hide_label: true
- suggestions << [user.recipient_label, recipients]
- suggestions.each_slice(4) do |slice|
Expand Down
2 changes: 2 additions & 0 deletions app/views/distributions/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
%thead
%tr
%th Recipient
%th Comment
%th Address
%th Amount
%th Percentage
Expand All @@ -18,6 +19,7 @@
= link_to tip.user.recipient_label, tip.user
- else
Nobody
%td.comment= tip.comment
%td.address
- if tip.user.try(:bitcoin_address).present?
= tip.user.bitcoin_address
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ en:
detailed_description: Detailed description
tip:
coin_amount: Amount
description: Comment
5 changes: 5 additions & 0 deletions db/migrate/20140601144116_add_comment_to_tip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCommentToTip < ActiveRecord::Migration
def change
add_column :tips, :comment, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140601104108) do
ActiveRecord::Schema.define(version: 20140601144116) do

create_table "cold_storage_transfers", force: true do |t|
t.integer "project_id"
Expand Down Expand Up @@ -109,6 +109,7 @@
t.integer "project_id"
t.datetime "refunded_at"
t.string "commit_message"
t.string "comment"
end

add_index "tips", ["distribution_id"], name: "index_tips_on_distribution_id"
Expand Down
20 changes: 20 additions & 0 deletions features/distribution.feature
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,23 @@ Feature: Fundraisers can distribute funds
| mubmzLrtTgDE2WrHkiwSFKuTh2VTSXboYK | 10.0 |
And the project balance should be "490.00"

@javascript
Scenario: Send distribution with a comment
Given a GitHub user "bob" who has set his address to "mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1"

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

When I'm logged in as "alice"
And I go to the project page
And I click on "New distribution"
And I type "bob" in the recipient field
And I select the recipient "bob"
And I fill the amount to "bob" with "10"
And I fill the comment to "bob" with "Great idea"
And I click on "Save"

Then I should see these distribution lines:
| recipient | address | comment | amount | percentage |
| bob | mxWfjaZJTNN5QKeZZYQ5HW3vgALFBsnuG1 | Great idea | 10 | 100 |
7 changes: 7 additions & 0 deletions features/step_definitions/distribution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
end
end

Given(/^I fill the comment to "(.*?)" with "(.*?)"$/) do |arg1, arg2|
within "#recipients tr", text: /^#{Regexp.escape arg1}/ do
fill_in "Comment", with: arg2
end
end

Then(/^I should see these distribution lines:$/) do |table|
table.hashes.each do |row|
begin
Expand All @@ -39,6 +45,7 @@
tr.find(".address").text.should eq(row["address"])
tr.find(".amount").should have_content(row["amount"])
tr.find(".percentage").should have_content(row["percentage"])
tr.find(".comment").should have_content(row["comment"]) if row["comment"]
end
end

Expand Down

0 comments on commit a4f2b16

Please sign in to comment.