- <% if member.phone.present? && !member.phone.blank? %>
+ <% if member.phone.present? %>
<%= phone_to member.phone %>
<% end %>
- <% if member.mail_to.present? && !member.mail_to.blank? %>
+ <% if member.mail_to.present? %>
<%= member.mail_to %>
diff --git a/config/locales/ca.yml b/config/locales/ca.yml
index 46ba2cd5f..201011210 100644
--- a/config/locales/ca.yml
+++ b/config/locales/ca.yml
@@ -494,6 +494,8 @@ ca:
minute:
one: "%{count} minut"
other: "%{count} minuts"
+ new:
+ error_amount: El temps ha de ser més gran que 0
users:
edit:
edit_user: Canviar usuari
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 8c5b4361b..199e837fc 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -494,6 +494,8 @@ en:
minute:
one: "%{count} minute"
other: "%{count} minutes"
+ new:
+ error_amount: Time must be greater than 0
users:
edit:
edit_user: Update user
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 47a045be9..b9654ca8f 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -494,6 +494,8 @@ es:
minute:
one: "%{count} minuto"
other: "%{count} minutos"
+ new:
+ error_amount: 'El tiempo debe ser mayor que 0 '
users:
edit:
edit_user: Cambiar usuario
diff --git a/config/locales/eu.yml b/config/locales/eu.yml
index ee6060db4..b2cf066e8 100644
--- a/config/locales/eu.yml
+++ b/config/locales/eu.yml
@@ -500,6 +500,8 @@ eu:
minute:
one: "%{count}minutu"
other: "%{count} minutu"
+ new:
+ error_amount:
users:
edit:
edit_user: Erabiltzailea aldatu
diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml
index a1b31f8c6..b3c5fde3f 100644
--- a/config/locales/pt-BR.yml
+++ b/config/locales/pt-BR.yml
@@ -494,6 +494,8 @@ pt-BR:
minute:
one: "%{count} minuto"
other: "%{count} minutos"
+ new:
+ error_amount:
users:
edit:
edit_user: Trocar usuário
diff --git a/db/migrate/20181004200104_add_amount_constraint_to_movements.rb b/db/migrate/20181004200104_add_amount_constraint_to_movements.rb
new file mode 100644
index 000000000..978eb0269
--- /dev/null
+++ b/db/migrate/20181004200104_add_amount_constraint_to_movements.rb
@@ -0,0 +1,10 @@
+class AddAmountConstraintToMovements < ActiveRecord::Migration
+ def change
+ # Destroy movements (and parent transfer) with amount equal to 0
+ Movement.includes(:transfer).where(amount: 0).find_each do |movement|
+ movement.transfer&.destroy
+ end
+
+ execute 'ALTER TABLE movements ADD CONSTRAINT non_zero_amount CHECK(amount != 0)'
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 151afa5d2..38963d039 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20180924164456) do
+ActiveRecord::Schema.define(version: 20181004200104) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
diff --git a/docs/CONTRIBUTING.en.md b/docs/CONTRIBUTING.en.md
index 9ed140e25..3e168d3ca 100644
--- a/docs/CONTRIBUTING.en.md
+++ b/docs/CONTRIBUTING.en.md
@@ -3,7 +3,7 @@
Did you find a bug? Do you want to collaborate?
Process:
-* Open a thread in [discourse](http://community.coopdevs.org/) to make sure whether it's a bug or a feature :wink:
+* Open a thread in [discourse](https://community.coopdevs.org/c/timeoverflow) to make sure whether it's a bug or a feature :wink:
* Once we understand what the bug is about and know the steps to reproduce we will create an issue in GitHub linking to the Discourse thread.
* Create a pull request to solve the issue.
* Report back to the discourse thread the bug has been solved linking to the pull request.
diff --git a/spec/controllers/transfers_controller_spec.rb b/spec/controllers/transfers_controller_spec.rb
index 7eff15bb6..c075091ec 100644
--- a/spec/controllers/transfers_controller_spec.rb
+++ b/spec/controllers/transfers_controller_spec.rb
@@ -207,5 +207,22 @@
end
end
end
+
+ context 'with invalid params' do
+ let(:user) { member_giver.user }
+ let(:referer) { "/transfers/new?destination_account_id=#{member_taker.account.id}" }
+
+ before do
+ request.env["HTTP_REFERER"] = referer
+ end
+
+ it 'does not create any Transfer and redirects to :back if the amount is 0' do
+ expect {
+ post(:create, transfer: { amount: 0, destination: member_taker.account.id })
+ }.not_to change(Transfer, :count)
+
+ expect(response).to redirect_to(referer)
+ end
+ end
end
end
diff --git a/spec/services/push_notifications/post_spec.rb b/spec/services/push_notifications/post_spec.rb
index 43d2b6165..d4b312818 100644
--- a/spec/services/push_notifications/post_spec.rb
+++ b/spec/services/push_notifications/post_spec.rb
@@ -13,10 +13,71 @@
end
describe '#create!' do
- it 'creates as many PushNotification resources as needed' do
- expect {
- creator.create!
- }.to change{PushNotification.count}.by(1)
+ context 'integration' do
+ it 'creates as many PushNotification resources as needed' do
+ expect { creator.create! }.to change { PushNotification.count }.by(1)
+ end
+ end
+
+ context 'unit' do
+ let(:post) do
+ Fabricate(
+ :post,
+ organization: organization,
+ user: user,
+ description: description
+ )
+ end
+
+ before { allow(PushNotification).to receive(:create!) }
+
+ context 'when the post description is empty' do
+ let(:description) { '' }
+
+ it 'creates a PushNotification with a default body' do
+ creator.create!
+
+ expect(PushNotification)
+ .to have_received(:create!)
+ .with(include(body: 'No description'))
+ end
+ end
+
+ context 'when the post description is nil' do
+ let(:description) { nil }
+
+ it 'creates a PushNotification with a default body' do
+ creator.create!
+
+ expect(PushNotification)
+ .to have_received(:create!)
+ .with(include(body: 'No description'))
+ end
+ end
+
+ context 'when the post description is shorter than 20 chars' do
+ let(:description) { 'description' }
+
+ it 'creates a PushNotification with the post body' do
+ creator.create!
+
+ expect(PushNotification)
+ .to have_received(:create!)
+ .with(include(body: post.description))
+ end
+ end
+
+ context 'when the post description is larger than 20 chars' do
+ let(:description) { 'this is a very long description' }
+
+ it 'creates a PushNotification with the post body truncated' do
+ creator.create!
+
+ expect(PushNotification)
+ .to have_received(:create!)
+ .with(include(body: post.description.truncate(20)))
+ end
+ end
end
end
end