Sha256: 42c2cc35e0ba9ea3eeafceb03a8b57d9cf85e794b2eea7fbabe47dcb3efe546b

Contents?: true

Size: 957 Bytes

Versions: 3

Compression:

Stored size: 957 Bytes

Contents

require 'test_helper'

class LocationResponder < ActionController::Responder
  include Responders::LocationResponder
end

class LocationsController < ApplicationController
  self.responder = LocationResponder

  respond_to :html
  before_filter :set_resource

  def create
    respond_with @resource, location: -> { 'given_location' }
  end

  def update
    respond_with @resource, location: 'given_location'
  end

  def set_resource
    @resource = Address.new
    @resource.errors[:fail] << "FAIL" if params[:fail]
  end
end

class LocationResponderTest < ActionController::TestCase
  tests LocationsController

  def test_redirects_to_block_location_on_success
    post :create
    assert_redirected_to 'given_location'
  end

  def test_renders_page_on_fail
    post :create, fail: true
    assert @response.body.include?('new.html.erb')
  end

  def test_redirects_to_plain_string
    post :update
    assert_redirected_to 'given_location'
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
responders-1.1.2 test/location_responder_test.rb
responders-1.1.1 test/location_responder_test.rb
responders-1.1.0 test/location_responder_test.rb