File: assigns_test.rb

package info (click to toggle)
ruby-rails-controller-testing 1.0.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,016 kB
  • sloc: ruby: 646; makefile: 4
file content (27 lines) | stat: -rw-r--r-- 795 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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