diff --git a/app/controllers/cypress/factories_controller.rb b/app/controllers/cypress/factories_controller.rb index db0677755..157e9e331 100644 --- a/app/controllers/cypress/factories_controller.rb +++ b/app/controllers/cypress/factories_controller.rb @@ -13,8 +13,14 @@ def create raise(ArgumentError, msg) end - attributes = params_to_attributes(params.except(:controller, :action, :number)) - res = FactoryBot.create(*attributes) + attributes, should_validate = params_to_attributes(params.except(:controller, :action, + :number)) + + res = if should_validate + FactoryBot.create(*attributes) # default case + else + FactoryBot.build(*attributes).tap { |instance| instance.save(validate: false) } + end render json: res.to_json, status: :created end @@ -22,15 +28,23 @@ def create private def params_to_attributes(params) - params.to_unsafe_hash.map do |_key, value| + should_validate = true + + attributes = params.to_unsafe_hash.filter_map do |_key, value| if value.is_a?(Hash) - value.transform_keys(&:to_sym) + if value.key?("validate") + should_validate = (value["validate"] != "false") + else + value.transform_keys(&:to_sym) + end elsif value.is_a?(String) value.to_sym else throw("Value is neither a hash nor a string: #{value}") end end + + return attributes, should_validate end end end diff --git a/docker/test/docker-compose.yml b/docker/test/docker-compose.yml index 34916abd1..d795b4ad3 100644 --- a/docker/test/docker-compose.yml +++ b/docker/test/docker-compose.yml @@ -38,7 +38,7 @@ services: dockerfile: docker/test/Dockerfile image: mampf:tests ports: - - "3000:3000" + - "3100:3000" environment: RAILS_ENV: test TEST_DATABASE_ADAPTER: postgresql diff --git a/spec/cypress/support/factorybot.js b/spec/cypress/support/factorybot.js index fc1d4b05e..973ffacd0 100644 --- a/spec/cypress/support/factorybot.js +++ b/spec/cypress/support/factorybot.js @@ -17,6 +17,11 @@ class FactoryBot { create(...args) { return BackendCaller.callCypressRoute("factories", "FactoryBot.create()", args); } + + createNoValidate(...args) { + args.push({ validate: false }); + return this.create(...args); + } } export default new FactoryBot();