Skip to content

Commit 1a68f29

Browse files
authored
Merge pull request #231 from coopdevs/disable-auto-payment
Disable auto payment
2 parents 3450fb0 + c6f4fc9 commit 1a68f29

File tree

8 files changed

+40
-7
lines changed

8 files changed

+40
-7
lines changed

Gemfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ end
6464
group :test do
6565
# Needed for TravisCI
6666
gem 'rake'
67-
gem "database_cleaner"
67+
68+
# Do not upgrade until
69+
# https://github.com/DatabaseCleaner/database_cleaner/issues/317 is fixed
70+
gem "database_cleaner", '1.3.0'
71+
6872
gem 'shoulda', ">= 3.5"
6973
gem 'fabrication'
7074
gem 'faker'

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ GEM
111111
concurrent-ruby (1.0.1)
112112
daemons (1.1.9)
113113
dalli (2.7.2)
114-
database_cleaner (1.4.0)
114+
database_cleaner (1.3.0)
115115
debug_inspector (0.0.2)
116116
devise (3.5.6)
117117
bcrypt (~> 3.0)
@@ -360,7 +360,7 @@ DEPENDENCIES
360360
capybara (~> 2.4.4)
361361
coffee-rails
362362
dalli
363-
database_cleaner
363+
database_cleaner (= 1.3.0)
364364
devise (= 3.5.6)
365365
dotenv-rails
366366
elasticsearch-model

app/controllers/transfers_controller.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
class TransfersController < ApplicationController
22
def create
33
@source = find_source
4-
Transfer.create(transfer_params.merge source: @source)
54
@account = Account.find(transfer_params[:destination])
5+
transfer = Transfer.new(
6+
transfer_params.merge(source: @source, destination: @account)
7+
)
8+
9+
begin
10+
transfer.save!
11+
rescue ActiveRecord::RecordInvalid
12+
flash[:error] = transfer.errors.full_messages.to_sentence
13+
end
614
redirect_to redirect_target
715
end
816

app/models/transfer.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class Transfer < ActiveRecord::Base
1717
belongs_to :operator, class_name: "User"
1818
has_many :movements
1919

20+
validate :different_source_and_destination
21+
2022
after_create :make_movements
2123

2224
def make_movements
@@ -39,4 +41,9 @@ def source_id
3941
def destination_id
4042
destination.respond_to?(:id) ? destination.id : destination
4143
end
44+
45+
def different_source_and_destination
46+
return unless source == destination
47+
errors.add(:base, :same_account)
48+
end
4249
end

app/views/users/show.html.erb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@
9393
<%= strip_tags(post.rendered_description.to_html) %>
9494
</div>
9595
<div class="col-sm-1">
96-
<%= link_to glyph(:time),
97-
give_time_user_path(@user, offer: post.id),
98-
title: t("global.give_time") %>
96+
<% if @user != current_user %>
97+
<%= link_to give_time_user_path(@user, offer: post.id) do %>
98+
<%= glyph :time %>
99+
<% end %>
100+
<% end %>
99101
</div>
100102
</div>
101103
<% end %>

config/locales/ca.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ ca:
102102
attributes:
103103
web:
104104
url_format_invalid: Format de URL no vàlid
105+
transfer:
106+
attributes:
107+
base:
108+
same_account: No es pot fer una transacció al mateix compte
105109

106110
# ETIQUETAS VARIADAS EN PLANTILLAS
107111

config/locales/en.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ en:
102102
attributes:
103103
web:
104104
url_format_invalid: invalid URL format
105+
transfer:
106+
attributes:
107+
base:
108+
same_account: A transfer cannot be made to the same account
105109

106110
# ETIQUETAS VARIADAS EN PLANTILLAS
107111

config/locales/es.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ es:
102102
attributes:
103103
web:
104104
url_format_invalid: Formato de URL no válido
105+
transfer:
106+
attributes:
107+
base:
108+
same_account: No se puede hacer una transacción a la misma cuenta
105109

106110
# ETIQUETAS VARIADAS EN PLANTILLAS
107111

0 commit comments

Comments
 (0)