Created
March 5, 2014 20:14
-
-
Save biscuitvile/9375660 to your computer and use it in GitHub Desktop.
Errors getting swallowed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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