Skip to content

Instantly share code, notes, and snippets.

@biscuitvile
Created March 5, 2014 20:14
Show Gist options
  • Select an option

  • Save biscuitvile/9375660 to your computer and use it in GitHub Desktop.

Select an option

Save biscuitvile/9375660 to your computer and use it in GitHub Desktop.
Errors getting swallowed
class SettingsController < ApplicationController
layout 'main', only: [:more]
def edit
@account = client.account
end
def edit
@form = SettingsUpdate.new(account: client.account)
end
def update
@form = SettingsUpdate.new(account_params.merge(account: client.account))
if @form.save
redirect_to edit_settings_path, notice: 'Your settings were successfully updated.'
else
flash.now[:error] = presented_errors
render :edit
end
end
def more
@account = client.account
end
private
def account_params
params.permit(
:store_name,
:description,
:contact_email,
)
end
def presented_errors
ErrorMessagesPresenter.new(@form.errors.messages).errors
end
end
require 'rails_helper'
describe SettingsController do
describe "#update" do
let(:client) { Minitest::Mock.new }
let(:account) { Minitest::Mock.new }
before do
mock(@controller).client.any_times { client }
mock(client).account.any_times { account }
end
it "initializes a form with account params and the current account" do
expected_arguments = { store_name: 'foo', account: account }
mock(SettingsUpdate).new
put :update, store_name: 'foo'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment