Sha256: 0ff6e37f4a00453fb049b3008b5780a68ca2b406ef2b1140a23d082dc8dcdf4e

Contents?: true

Size: 795 Bytes

Versions: 7

Compression:

Stored size: 795 Bytes

Contents

require 'test_helper'

class AssignsControllerTest < ActionController::TestCase
  def test_assigns
    process :test_assigns
    # assigns can be accessed using assigns(key)
    # or assigns[key], where key is a string or
    # a symbol
    assert_equal "foo", assigns(:foo)
    assert_equal "foo", assigns("foo")
    assert_equal "foo", assigns[:foo]
    assert_equal "foo", assigns["foo"]

    # but the assigned variable should not have its own keys stringified
    expected_hash = { foo: :bar }
    assert_equal expected_hash, assigns(:foo_hash)
  end

  def test_view_assigns
    @controller = ViewAssignsController.new
    process :test_assigns
    assert_nil assigns(:foo)
    assert_nil assigns[:foo]
    assert_equal "bar", assigns(:bar)
    assert_equal "bar", assigns[:bar]
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rails-controller-testing-1.0.5/test/controllers/assigns_test.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rails-controller-testing-1.0.5/test/controllers/assigns_test.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rails-controller-testing-1.0.5/test/controllers/assigns_test.rb
rails-controller-testing-1.0.5 test/controllers/assigns_test.rb
rails-controller-testing-1.0.4 test/controllers/assigns_test.rb
rails-controller-testing-1.0.3 test/controllers/assigns_test.rb
rails-controller-testing-1.0.2 test/controllers/assigns_test.rb