From ea73b9a88b366f37ccc2a536c1a0f26c66e58d11 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 30 Aug 2016 14:48:22 +0200 Subject: [PATCH] fix create event without custom price + fix test fixtures --- app/controllers/api/events_controller.rb | 8 +++++--- test/fixtures/price_categories.yml | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/events_controller.rb b/app/controllers/api/events_controller.rb index 40204919f..a02590a9b 100644 --- a/app/controllers/api/events_controller.rb +++ b/app/controllers/api/events_controller.rb @@ -88,9 +88,11 @@ class API::EventsController < API::ApiController # convert main price to centimes event_preparams.merge!(amount: (event_preparams[:amount].to_i * 100 if event_preparams[:amount].present?)) # delete non-complete "other" prices and convert them to centimes - event_preparams[:event_price_categories_attributes].delete_if { |price_cat| price_cat[:price_category_id].empty? or price_cat[:amount].empty? } - event_preparams[:event_price_categories_attributes].each do |price_cat| - price_cat[:amount] = price_cat[:amount].to_i * 100 + unless event_preparams[:event_price_categories_attributes].nil? + event_preparams[:event_price_categories_attributes].delete_if { |price_cat| price_cat[:price_category_id].empty? or price_cat[:amount].empty? } + event_preparams[:event_price_categories_attributes].each do |price_cat| + price_cat[:amount] = price_cat[:amount].to_i * 100 + end end # return the resulting params object event_preparams diff --git a/test/fixtures/price_categories.yml b/test/fixtures/price_categories.yml index 2ff75a802..693bc4376 100644 --- a/test/fixtures/price_categories.yml +++ b/test/fixtures/price_categories.yml @@ -1,9 +1,9 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: - name: MyString - description: MyText + name: "- de 25 ans" + conditions: "Tarif réservé aux jeunes de moins de 25 ans" two: - name: MyString - description: MyText + name: "chômeurs" + conditions: "Tarif préférentiel pour les demandeurs d'emploi pouvant justifier de leur situation."