Class: HasScopeTest
- Inherits:
-
ActionController::TestCase
- Object
- ActionController::TestCase
- HasScopeTest
- Defined in:
- lib/vendor/plugins/inherited_resources/test/has_scope_test.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #test_boolean_scope_is_called_when_boolean_param_is_false ⇒ Object
- #test_boolean_scope_is_called_when_boolean_param_is_true ⇒ Object
- #test_default_scope_value_can_be_overwritten ⇒ Object
- #test_multiple_scopes_are_called ⇒ Object
- #test_scope_is_called_except_on_index ⇒ Object
- #test_scope_is_called_only_on_index ⇒ Object
- #test_scope_is_called_with_arguments ⇒ Object
- #test_scope_is_called_with_default_value ⇒ Object
- #test_scope_is_skipped_when_if_option_is_false ⇒ Object
- #test_scope_is_skipped_when_unless_option_is_true ⇒ Object
- #test_scope_with_default_value_as_proc ⇒ Object
- #test_scope_with_different_key ⇒ Object
Instance Method Details
#setup ⇒ Object
27 28 29 30 |
# File 'lib/vendor/plugins/inherited_resources/test/has_scope_test.rb', line 27 def setup @controller.stubs(:resource_url).returns('/') @controller.stubs(:collection_url).returns('/') end |
#test_boolean_scope_is_called_when_boolean_param_is_false ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/vendor/plugins/inherited_resources/test/has_scope_test.rb', line 40 def test_boolean_scope_is_called_when_boolean_param_is_false Tree.expects(:only_tall).never Tree.expects(:find).with(:all).returns([mock_tree]) get :index, :only_tall => 'false' assert_equal([mock_tree], assigns(:trees)) assert_equal({ :only_tall => 'false' }, assigns(:current_scopes)) end |
#test_boolean_scope_is_called_when_boolean_param_is_true ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/vendor/plugins/inherited_resources/test/has_scope_test.rb', line 32 def test_boolean_scope_is_called_when_boolean_param_is_true Tree.expects(:only_tall).with().returns(Tree).in_sequence Tree.expects(:find).with(:all).returns([mock_tree]).in_sequence get :index, :only_tall => 'true' assert_equal([mock_tree], assigns(:trees)) assert_equal({ :only_tall => 'true' }, assigns(:current_scopes)) end |
#test_default_scope_value_can_be_overwritten ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/vendor/plugins/inherited_resources/test/has_scope_test.rb', line 107 def test_default_scope_value_can_be_overwritten Tree.expects(:shadown_range).with('20').returns(Tree).in_sequence Tree.expects(:find).with('42').returns(mock_tree).in_sequence get :edit, :id => '42', :shadown_range => '20' assert_equal(mock_tree, assigns(:tree)) assert_equal({ :shadown_range => '20' }, assigns(:current_scopes)) end |
#test_multiple_scopes_are_called ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/vendor/plugins/inherited_resources/test/has_scope_test.rb', line 90 def test_multiple_scopes_are_called Tree.expects(:only_tall).with().returns(Tree) Tree.expects(:color).with('blue').returns(Tree) Tree.expects(:find).with(:all).returns([mock_tree]) get :index, :color => 'blue', :only_tall => 'true' assert_equal([mock_tree], assigns(:trees)) assert_equal({ :color => 'blue', :only_tall => 'true' }, assigns(:current_scopes)) end |
#test_scope_is_called_except_on_index ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/vendor/plugins/inherited_resources/test/has_scope_test.rb', line 74 def test_scope_is_called_except_on_index Tree.expects(:shadown_range).with().never Tree.expects(:find).with(:all).returns([mock_tree]) get :index, :shadown_range => 20 assert_equal([mock_tree], assigns(:trees)) assert_equal({ }, assigns(:current_scopes)) end |
#test_scope_is_called_only_on_index ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/vendor/plugins/inherited_resources/test/has_scope_test.rb', line 48 def test_scope_is_called_only_on_index Tree.expects(:only_tall).never Tree.expects(:find).with('42').returns(mock_tree) get :show, :only_tall => 'true', :id => '42' assert_equal(mock_tree, assigns(:tree)) assert_equal({ }, assigns(:current_scopes)) end |
#test_scope_is_called_with_arguments ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/vendor/plugins/inherited_resources/test/has_scope_test.rb', line 82 def test_scope_is_called_with_arguments Tree.expects(:color).with('blue').returns(Tree).in_sequence Tree.expects(:find).with(:all).returns([mock_tree]).in_sequence get :index, :color => 'blue' assert_equal([mock_tree], assigns(:trees)) assert_equal({ :color => 'blue' }, assigns(:current_scopes)) end |
#test_scope_is_called_with_default_value ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/vendor/plugins/inherited_resources/test/has_scope_test.rb', line 99 def test_scope_is_called_with_default_value Tree.expects(:shadown_range).with(10).returns(Tree).in_sequence Tree.expects(:find).with('42').returns(mock_tree).in_sequence get :edit, :id => '42' assert_equal(mock_tree, assigns(:tree)) assert_equal({ :shadown_range => 10 }, assigns(:current_scopes)) end |
#test_scope_is_skipped_when_if_option_is_false ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/vendor/plugins/inherited_resources/test/has_scope_test.rb', line 56 def test_scope_is_skipped_when_if_option_is_false @controller.stubs(:restrict_to_only_tall_trees?).returns(false) Tree.expects(:only_tall).never Tree.expects(:find).with(:all).returns([mock_tree]) get :index, :only_tall => 'true' assert_equal([mock_tree], assigns(:trees)) assert_equal({ }, assigns(:current_scopes)) end |
#test_scope_is_skipped_when_unless_option_is_true ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/vendor/plugins/inherited_resources/test/has_scope_test.rb', line 65 def test_scope_is_skipped_when_unless_option_is_true @controller.stubs(:show_all_colors?).returns(true) Tree.expects(:color).never Tree.expects(:find).with(:all).returns([mock_tree]) get :index, :color => 'blue' assert_equal([mock_tree], assigns(:trees)) assert_equal({ }, assigns(:current_scopes)) end |
#test_scope_with_default_value_as_proc ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'lib/vendor/plugins/inherited_resources/test/has_scope_test.rb', line 123 def test_scope_with_default_value_as_proc session[:height] = 100 Tree.expects(:calculate_height).with(100).returns(Tree).in_sequence Tree.expects(:new).returns(mock_tree).in_sequence get :new assert_equal(mock_tree, assigns(:tree)) assert_equal({ :calculate_height => 100 }, assigns(:current_scopes)) end |
#test_scope_with_different_key ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/vendor/plugins/inherited_resources/test/has_scope_test.rb', line 115 def test_scope_with_different_key Tree.expects(:root_type).with('outside').returns(Tree).in_sequence Tree.expects(:find).with('42').returns(mock_tree).in_sequence get :show, :id => '42', :root => 'outside' assert_equal(mock_tree, assigns(:tree)) assert_equal({ :root => 'outside' }, assigns(:current_scopes)) end |