inherited_resources 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/lib/inherited_resources/version.rb +1 -1
  3. metadata +13 -218
  4. data/.gitignore +0 -1
  5. data/CHANGELOG +0 -172
  6. data/Gemfile +0 -10
  7. data/Gemfile.lock +0 -71
  8. data/Rakefile +0 -24
  9. data/inherited_resources.gemspec +0 -25
  10. data/test/aliases_test.rb +0 -146
  11. data/test/association_chain_test.rb +0 -125
  12. data/test/base_test.rb +0 -334
  13. data/test/belongs_to_test.rb +0 -130
  14. data/test/belongs_to_with_shallow_test.rb +0 -93
  15. data/test/class_methods_test.rb +0 -185
  16. data/test/customized_base_test.rb +0 -168
  17. data/test/customized_belongs_to_test.rb +0 -76
  18. data/test/customized_redirect_to_test.rb +0 -32
  19. data/test/defaults_test.rb +0 -197
  20. data/test/locales/en.yml +0 -17
  21. data/test/multiple_nested_optional_belongs_to_test.rb +0 -369
  22. data/test/nested_belongs_to_test.rb +0 -108
  23. data/test/nested_belongs_to_with_shallow_test.rb +0 -123
  24. data/test/nested_model_with_shallow_test.rb +0 -147
  25. data/test/nested_singleton_test.rb +0 -167
  26. data/test/optional_belongs_to_test.rb +0 -164
  27. data/test/polymorphic_test.rb +0 -215
  28. data/test/redirect_to_test.rb +0 -51
  29. data/test/singleton_test.rb +0 -87
  30. data/test/strong_parameters_test.rb +0 -120
  31. data/test/test_helper.rb +0 -47
  32. data/test/url_helpers_test.rb +0 -988
  33. data/test/views/address/edit.html.erb +0 -1
  34. data/test/views/address/new.html.erb +0 -1
  35. data/test/views/address/show.html.erb +0 -1
  36. data/test/views/cars/edit.html.erb +0 -1
  37. data/test/views/cars/index.html.erb +0 -1
  38. data/test/views/cars/new.html.erb +0 -1
  39. data/test/views/cars/show.html.erb +0 -1
  40. data/test/views/cities/edit.html.erb +0 -1
  41. data/test/views/cities/index.html.erb +0 -1
  42. data/test/views/cities/new.html.erb +0 -1
  43. data/test/views/cities/show.html.erb +0 -1
  44. data/test/views/comments/edit.html.erb +0 -1
  45. data/test/views/comments/index.html.erb +0 -1
  46. data/test/views/comments/new.html.erb +0 -1
  47. data/test/views/comments/show.html.erb +0 -1
  48. data/test/views/educations/new.html.erb +0 -0
  49. data/test/views/employees/edit.html.erb +0 -1
  50. data/test/views/employees/index.html.erb +0 -1
  51. data/test/views/employees/new.html.erb +0 -1
  52. data/test/views/employees/show.html.erb +0 -1
  53. data/test/views/geolocation/show.html.erb +0 -1
  54. data/test/views/groups/edit.html.erb +0 -0
  55. data/test/views/managers/edit.html.erb +0 -1
  56. data/test/views/managers/new.html.erb +0 -1
  57. data/test/views/managers/show.html.erb +0 -1
  58. data/test/views/painters/edit.html.erb +0 -1
  59. data/test/views/painters/index.html.erb +0 -1
  60. data/test/views/painters/new.html.erb +0 -1
  61. data/test/views/painters/show.html.erb +0 -1
  62. data/test/views/pets/edit.html.erb +0 -1
  63. data/test/views/pets/index.html.erb +0 -1
  64. data/test/views/pets/new.html.erb +0 -1
  65. data/test/views/pets/show.html.erb +0 -1
  66. data/test/views/photos/index.html.erb +0 -1
  67. data/test/views/plates/edit.html.erb +0 -1
  68. data/test/views/plates/index.html.erb +0 -1
  69. data/test/views/plates/new.html.erb +0 -1
  70. data/test/views/plates/show.html.erb +0 -1
  71. data/test/views/products/edit.html.erb +0 -1
  72. data/test/views/products/index.html.erb +0 -1
  73. data/test/views/products/new.html.erb +0 -1
  74. data/test/views/products/show.html.erb +0 -1
  75. data/test/views/professors/edit.html.erb +0 -1
  76. data/test/views/professors/index.html.erb +0 -1
  77. data/test/views/professors/new.html.erb +0 -1
  78. data/test/views/professors/show.html.erb +0 -1
  79. data/test/views/projects/edit.html.erb +0 -1
  80. data/test/views/projects/index.html.erb +0 -1
  81. data/test/views/projects/index.json.erb +0 -1
  82. data/test/views/projects/new.html.erb +0 -1
  83. data/test/views/projects/respond_to_skip_default_template.html.erb +0 -1
  84. data/test/views/projects/respond_with_resource.html.erb +0 -1
  85. data/test/views/projects/show.html.erb +0 -1
  86. data/test/views/students/edit.html.erb +0 -1
  87. data/test/views/students/new.html.erb +0 -1
  88. data/test/views/tags/edit.html.erb +0 -1
  89. data/test/views/tags/index.html.erb +0 -1
  90. data/test/views/tags/new.html.erb +0 -1
  91. data/test/views/tags/show.html.erb +0 -1
  92. data/test/views/trees/edit.html.erb +0 -1
  93. data/test/views/trees/index.html.erb +0 -1
  94. data/test/views/trees/new.html.erb +0 -1
  95. data/test/views/trees/show.html.erb +0 -1
  96. data/test/views/university/professors/edit.html.erb +0 -1
  97. data/test/views/university/professors/index.html.erb +0 -1
  98. data/test/views/university/professors/new.html.erb +0 -1
  99. data/test/views/university/professors/show.html.erb +0 -1
  100. data/test/views/users/create.js.erb +0 -1
  101. data/test/views/users/destroy.js.erb +0 -1
  102. data/test/views/users/edit.html.erb +0 -1
  103. data/test/views/users/index.html.erb +0 -1
  104. data/test/views/users/new.html.erb +0 -1
  105. data/test/views/users/show.html.erb +0 -1
  106. data/test/views/users/update.js.erb +0 -1
  107. data/test/views/venue/show.html.erb +0 -1
  108. data/test/views/widgets/new.html.erb +0 -0
data/Gemfile DELETED
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'mocha'
6
- gem 'minitest-rg'
7
-
8
- group :test do
9
- gem 'strong_parameters'
10
- end
data/Gemfile.lock DELETED
@@ -1,71 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- inherited_resources (1.5.1)
5
- actionpack (>= 3.2, < 4.2)
6
- has_scope (~> 0.6.0.rc)
7
- railties (>= 3.2, < 4.2)
8
- responders (~> 1.0)
9
-
10
- GEM
11
- remote: https://rubygems.org/
12
- specs:
13
- actionpack (4.1.5)
14
- actionview (= 4.1.5)
15
- activesupport (= 4.1.5)
16
- rack (~> 1.5.2)
17
- rack-test (~> 0.6.2)
18
- actionview (4.1.5)
19
- activesupport (= 4.1.5)
20
- builder (~> 3.1)
21
- erubis (~> 2.7.0)
22
- activemodel (4.1.5)
23
- activesupport (= 4.1.5)
24
- builder (~> 3.1)
25
- activesupport (4.1.5)
26
- i18n (~> 0.6, >= 0.6.9)
27
- json (~> 1.7, >= 1.7.7)
28
- minitest (~> 5.1)
29
- thread_safe (~> 0.1)
30
- tzinfo (~> 1.1)
31
- builder (3.2.2)
32
- erubis (2.7.0)
33
- has_scope (0.6.0.rc)
34
- actionpack (>= 3.2, < 5)
35
- activesupport (>= 3.2, < 5)
36
- i18n (0.6.11)
37
- json (1.8.1)
38
- metaclass (0.0.4)
39
- minitest (5.4.1)
40
- minitest-rg (5.1.0)
41
- minitest (~> 5.0)
42
- mocha (1.1.0)
43
- metaclass (~> 0.0.1)
44
- rack (1.5.2)
45
- rack-test (0.6.2)
46
- rack (>= 1.0)
47
- railties (4.1.5)
48
- actionpack (= 4.1.5)
49
- activesupport (= 4.1.5)
50
- rake (>= 0.8.7)
51
- thor (>= 0.18.1, < 2.0)
52
- rake (10.3.2)
53
- responders (1.1.1)
54
- railties (>= 3.2, < 4.2)
55
- strong_parameters (0.1.4)
56
- actionpack (>= 3.2.0)
57
- activemodel (>= 3.2.0)
58
- railties (>= 3.2.0)
59
- thor (0.19.1)
60
- thread_safe (0.3.4)
61
- tzinfo (1.2.2)
62
- thread_safe (~> 0.1)
63
-
64
- PLATFORMS
65
- ruby
66
-
67
- DEPENDENCIES
68
- inherited_resources!
69
- minitest-rg
70
- mocha
71
- strong_parameters
data/Rakefile DELETED
@@ -1,24 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rake/testtask'
5
- require 'rdoc/task'
6
-
7
- desc 'Run tests for InheritedResources.'
8
- Rake::TestTask.new(:test) do |t|
9
- t.pattern = 'test/**/*_test.rb'
10
- t.verbose = true
11
- end
12
-
13
- desc 'Generate documentation for InheritedResources.'
14
- Rake::RDocTask.new(:rdoc) do |rdoc|
15
- rdoc.rdoc_dir = 'rdoc'
16
- rdoc.title = 'InheritedResources'
17
- rdoc.options << '--line-numbers' << '--inline-source'
18
- rdoc.rdoc_files.include('README.rdoc')
19
- rdoc.rdoc_files.include('MIT-LICENSE')
20
- rdoc.rdoc_files.include('lib/**/*.rb')
21
- end
22
-
23
- # Make test the default task.
24
- task :default => :test
@@ -1,25 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "inherited_resources/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "inherited_resources"
7
- s.version = InheritedResources::VERSION.dup
8
- s.platform = Gem::Platform::RUBY
9
- s.summary = "Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important."
10
- s.homepage = "http://github.com/josevalim/inherited_resources"
11
- s.description = "Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important."
12
- s.authors = ['José Valim', 'Joel Moss']
13
- s.license = "MIT"
14
-
15
- s.rubyforge_project = "inherited_resources"
16
-
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.require_paths = ["lib"]
20
-
21
- s.add_dependency("responders", "~> 1.0")
22
- s.add_dependency("actionpack", ">= 3.2", "< 4.2")
23
- s.add_dependency("railties", ">= 3.2", "< 4.2")
24
- s.add_dependency("has_scope", "~> 0.6.0.rc")
25
- end
data/test/aliases_test.rb DELETED
@@ -1,146 +0,0 @@
1
- require File.expand_path('test_helper', File.dirname(__FILE__))
2
-
3
- class Student
4
- extend ActiveModel::Naming
5
- end
6
-
7
- class ApplicationController < ActionController::Base
8
- include InheritedResources::DSL
9
- end
10
-
11
- class StudentsController < ApplicationController
12
- inherit_resources
13
- respond_to :html, :xml
14
-
15
- def edit
16
- edit! do |format|
17
- format.xml { render :text => 'Render XML' }
18
- end
19
- end
20
-
21
- def new
22
- @something = 'magical'
23
- new!
24
- end
25
-
26
- create!(:location => "http://test.host/") do |success, failure|
27
- success.html { render :text => "I won't redirect!" }
28
- failure.xml { render :text => "I shouldn't be rendered" }
29
- end
30
-
31
- update! do |success, failure|
32
- success.html { redirect_to(resource_url) }
33
- failure.html { render :text => "I won't render!" }
34
- end
35
-
36
- destroy! do |format|
37
- format.html { render :text => "Destroyed!" }
38
- end
39
- end
40
-
41
- class AliasesTest < ActionController::TestCase
42
- tests StudentsController
43
-
44
- def test_assignments_before_calling_alias
45
- Student.stubs(:new).returns(mock_student)
46
- get :new
47
- assert_response :success
48
- assert_equal 'magical', assigns(:something)
49
- end
50
-
51
- def test_controller_should_render_new
52
- Student.stubs(:new).returns(mock_student)
53
- get :new
54
- assert_response :success
55
- assert_equal 'New HTML', @response.body.strip
56
- end
57
-
58
- def test_expose_the_requested_user_on_edit
59
- Student.expects(:find).with('42').returns(mock_student)
60
- get :edit, :id => '42'
61
- assert_equal mock_student, assigns(:student)
62
- assert_response :success
63
- end
64
-
65
- def test_controller_should_render_edit
66
- Student.stubs(:find).returns(mock_student)
67
- get :edit
68
- assert_response :success
69
- assert_equal 'Edit HTML', @response.body.strip
70
- end
71
-
72
- def test_render_xml_when_it_is_given_as_a_block
73
- @request.accept = 'application/xml'
74
- Student.stubs(:find).returns(mock_student)
75
- get :edit
76
- assert_response :success
77
- assert_equal 'Render XML', @response.body
78
- end
79
-
80
- def test_is_not_redirected_on_create_with_success_if_success_block_is_given
81
- Student.stubs(:new).returns(mock_student(:save => true))
82
- @controller.stubs(:resource_url).returns('http://test.host/')
83
- post :create
84
- assert_response :success
85
- assert_equal "I won't redirect!", @response.body
86
- end
87
-
88
- def test_dumb_responder_quietly_receives_everything_on_failure
89
- @request.accept = 'text/html'
90
- Student.stubs(:new).returns(mock_student(:save => false, :errors => {:some => :error}))
91
- @controller.stubs(:resource_url).returns('http://test.host/')
92
- post :create
93
- assert_response :success
94
- assert_equal "New HTML", @response.body.strip
95
- end
96
-
97
- def test_html_is_the_default_when_only_xml_is_overwriten
98
- @request.accept = '*/*'
99
- Student.stubs(:new).returns(mock_student(:save => false, :errors => {:some => :error}))
100
- @controller.stubs(:resource_url).returns('http://test.host/')
101
- post :create
102
- assert_response :success
103
- assert_equal "New HTML", @response.body.strip
104
- end
105
-
106
- def test_wont_render_edit_template_on_update_with_failure_if_failure_block_is_given
107
- Student.stubs(:find).returns(mock_student(:update_attributes => false, :errors => { :fail => true }))
108
- put :update
109
- assert_response :success
110
- assert_equal "I won't render!", @response.body
111
- end
112
-
113
- def test_dumb_responder_quietly_receives_everything_on_success
114
- Student.stubs(:find).returns(mock_student(:update_attributes => true))
115
- @controller.stubs(:resource_url).returns('http://test.host/')
116
- put :update, :id => '42', :student => {:these => 'params'}
117
- assert_equal mock_student, assigns(:student)
118
- end
119
-
120
- def test_block_is_called_when_student_is_destroyed
121
- Student.stubs(:find).returns(mock_student(:destroy => true))
122
- delete :destroy
123
- assert_response :success
124
- assert_equal "Destroyed!", @response.body
125
- end
126
-
127
- def test_options_are_used_in_respond_with
128
- @request.accept = "application/xml"
129
- mock_student = mock_student(:save => true, :to_xml => "XML")
130
- Student.stubs(:new).returns(mock_student)
131
-
132
- post :create
133
- assert_equal "http://test.host/", @response.location
134
- end
135
-
136
- protected
137
- def mock_student(expectations={})
138
- @mock_student ||= begin
139
- student = mock(expectations.except(:errors))
140
- student.stubs(:class).returns(Student)
141
- student.stubs(:errors).returns(expectations.fetch(:errors, {}))
142
- student
143
- end
144
- end
145
- end
146
-
@@ -1,125 +0,0 @@
1
- require File.expand_path('test_helper', File.dirname(__FILE__))
2
-
3
- class Pet
4
- extend ActiveModel::Naming
5
- end
6
-
7
- class Puppet
8
- extend ActiveModel::Naming
9
- end
10
-
11
- class PetsController < InheritedResources::Base
12
- attr_accessor :current_user
13
-
14
- def edit
15
- @pet = 'new pet'
16
- edit!
17
- end
18
-
19
- protected
20
- def collection
21
- @pets ||= end_of_association_chain.all
22
- end
23
-
24
- def begin_of_association_chain
25
- @current_user
26
- end
27
- end
28
-
29
- class BeginOfAssociationChainTest < ActionController::TestCase
30
- tests PetsController
31
-
32
- def setup
33
- @controller.current_user = mock()
34
- end
35
-
36
- def test_begin_of_association_chain_is_called_on_index
37
- @controller.current_user.expects(:pets).returns(Pet)
38
- Pet.expects(:all).returns(mock_pet)
39
- get :index
40
- assert_response :success
41
- assert_equal 'Index HTML', @response.body.strip
42
- end
43
-
44
- def test_begin_of_association_chain_is_called_on_new
45
- @controller.current_user.expects(:pets).returns(Pet)
46
- Pet.expects(:build).returns(mock_pet)
47
- get :new
48
- assert_response :success
49
- assert_equal 'New HTML', @response.body.strip
50
- end
51
-
52
- def test_begin_of_association_chain_is_called_on_show
53
- @controller.current_user.expects(:pets).returns(Pet)
54
- Pet.expects(:find).with('47').returns(mock_pet)
55
- get :show, :id => '47'
56
- assert_response :success
57
- assert_equal 'Show HTML', @response.body.strip
58
- end
59
-
60
- def test_instance_variable_should_not_be_set_if_already_defined
61
- @controller.current_user.expects(:pets).never
62
- Pet.expects(:find).never
63
- get :edit
64
- assert_response :success
65
- assert_equal 'new pet', assigns(:pet)
66
- end
67
-
68
- def test_model_is_not_initialized_with_nil
69
- @controller.current_user.expects(:pets).returns(Pet)
70
- Pet.expects(:build).with({}).returns(mock_pet)
71
- get :new
72
- assert_equal mock_pet, assigns(:pet)
73
- end
74
-
75
- def test_begin_of_association_chain_is_included_in_chain
76
- @controller.current_user.expects(:pets).returns(Pet)
77
- Pet.expects(:build).with({}).returns(mock_pet)
78
- get :new
79
- assert_equal [@controller.current_user], @controller.send(:association_chain)
80
- end
81
-
82
- protected
83
- def mock_pet(stubs={})
84
- @mock_pet ||= mock(stubs)
85
- end
86
-
87
- end
88
-
89
- class PuppetsController < InheritedResources::Base
90
- optional_belongs_to :pet
91
- end
92
-
93
- class AssociationChainTest < ActionController::TestCase
94
- tests PuppetsController
95
-
96
- def setup
97
- @controller.stubs(:resource_url).returns('/')
98
- @controller.stubs(:collection_url).returns('/')
99
- end
100
-
101
- def test_parent_is_added_to_association_chain
102
- Pet.expects(:find).with('37').returns(mock_pet)
103
- mock_pet.expects(:puppets).returns(Puppet)
104
- Puppet.expects(:find).with('42').returns(mock_puppet)
105
- mock_puppet.expects(:destroy)
106
- delete :destroy, :id => '42', :pet_id => '37'
107
- assert_equal [mock_pet], @controller.send(:association_chain)
108
- end
109
-
110
- def test_parent_is_added_to_association_chain_if_not_available
111
- Puppet.expects(:find).with('42').returns(mock_puppet)
112
- mock_puppet.expects(:destroy)
113
- delete :destroy, :id => '42'
114
- assert_equal [], @controller.send(:association_chain)
115
- end
116
-
117
- protected
118
- def mock_pet(stubs={})
119
- @mock_pet ||= mock(stubs)
120
- end
121
-
122
- def mock_puppet(stubs={})
123
- @mock_puppet ||= mock(stubs)
124
- end
125
- end
data/test/base_test.rb DELETED
@@ -1,334 +0,0 @@
1
- require File.expand_path('test_helper', File.dirname(__FILE__))
2
-
3
- class User
4
- extend ActiveModel::Naming
5
- end
6
-
7
- class AccountsController < InheritedResources::Base
8
- end
9
-
10
- class UsersController < AccountsController
11
- respond_to :html, :xml
12
- respond_to :js, :only => [:create, :update, :destroy]
13
- attr_reader :scopes_applied
14
-
15
- protected
16
-
17
- def apply_scopes(object)
18
- @scopes_applied = true
19
- object
20
- end
21
- end
22
-
23
- module UserTestHelper
24
- def setup
25
- @controller = UsersController.new
26
- @controller.request = @request = ActionController::TestRequest.new
27
- @controller.response = @response = ActionController::TestResponse.new
28
- @controller.stubs(:user_url).returns("/")
29
- end
30
-
31
- protected
32
-
33
- def mock_user(expectations={})
34
- @mock_user ||= begin
35
- user = mock(expectations.except(:errors))
36
- user.stubs(:class).returns(User)
37
- user.stubs(:errors).returns(expectations.fetch(:errors, {}))
38
- user.singleton_class.class_eval do
39
- def method_missing(symbol, *arguments, &block)
40
- raise NoMethodError.new('this is expected by Array#flatten') if symbol == :to_ary
41
- super
42
- end
43
- end
44
- user
45
- end
46
- end
47
- end
48
-
49
- class IndexActionBaseTest < ActionController::TestCase
50
- include UserTestHelper
51
-
52
- def test_expose_all_users_as_instance_variable
53
- User.expects(:scoped).returns([mock_user])
54
- get :index
55
- assert_equal [mock_user], assigns(:users)
56
- end
57
-
58
- def test_apply_scopes_if_method_is_available
59
- User.expects(:scoped).returns([mock_user])
60
- get :index
61
- assert @controller.scopes_applied
62
- end
63
-
64
- def test_controller_should_render_index
65
- User.stubs(:scoped).returns([mock_user])
66
- get :index
67
- assert_response :success
68
- assert_equal 'Index HTML', @response.body.strip
69
- end
70
-
71
- def test_render_all_users_as_xml_when_mime_type_is_xml
72
- @request.accept = 'application/xml'
73
- User.expects(:scoped).returns(collection = [mock_user])
74
- collection.expects(:to_xml).returns('Generated XML')
75
- get :index
76
- assert_response :success
77
- assert_equal 'Generated XML', @response.body
78
- end
79
-
80
- def test_scoped_is_called_only_when_available
81
- User.stubs(:all).returns([mock_user])
82
- get :index
83
- assert_equal Array, assigns(:users).class
84
- end
85
- end
86
-
87
- class ShowActionBaseTest < ActionController::TestCase
88
- include UserTestHelper
89
-
90
- def test_expose_the_requested_user
91
- User.expects(:find).with('42').returns(mock_user)
92
- get :show, :id => '42'
93
- assert_equal mock_user, assigns(:user)
94
- end
95
-
96
- def test_controller_should_render_show
97
- User.stubs(:find).returns(mock_user)
98
- get :show
99
- assert_response :success
100
- assert_equal 'Show HTML', @response.body.strip
101
- end
102
-
103
- def test_render_exposed_user_as_xml_when_mime_type_is_xml
104
- @request.accept = 'application/xml'
105
- User.expects(:find).with('42').returns(mock_user)
106
- mock_user.expects(:to_xml).returns("Generated XML")
107
-
108
- get :show, :id => '42'
109
- assert_response :success
110
- assert_equal 'Generated XML', @response.body
111
- end
112
- end
113
-
114
- class NewActionBaseTest < ActionController::TestCase
115
- include UserTestHelper
116
-
117
- def test_expose_a_new_user
118
- User.expects(:new).returns(mock_user)
119
- get :new
120
- assert_equal mock_user, assigns(:user)
121
- end
122
-
123
- def test_controller_should_render_new
124
- User.stubs(:new).returns(mock_user)
125
- get :new
126
- assert_response :success
127
- assert_equal 'New HTML', @response.body.strip
128
- end
129
-
130
- def test_render_exposed_a_new_user_as_xml_when_mime_type_is_xml
131
- @request.accept = 'application/xml'
132
- User.expects(:new).returns(mock_user)
133
- mock_user.expects(:to_xml).returns("Generated XML")
134
-
135
- get :new
136
- assert_response :success
137
- assert_equal 'Generated XML', @response.body
138
- end
139
- end
140
-
141
- class EditActionBaseTest < ActionController::TestCase
142
- include UserTestHelper
143
-
144
- def test_expose_the_requested_user
145
- User.expects(:find).with('42').returns(mock_user)
146
- get :edit, :id => '42'
147
- assert_response :success
148
- assert_equal mock_user, assigns(:user)
149
- end
150
-
151
- def test_controller_should_render_edit
152
- User.stubs(:find).returns(mock_user)
153
- get :edit
154
- assert_response :success
155
- assert_equal 'Edit HTML', @response.body.strip
156
- end
157
- end
158
-
159
- class CreateActionBaseTest < ActionController::TestCase
160
- include UserTestHelper
161
-
162
- def test_expose_a_newly_create_user_when_saved_with_success
163
- User.expects(:new).with({'these' => 'params'}).returns(mock_user(:save => true))
164
- post :create, :user => {:these => 'params'}
165
- assert_equal mock_user, assigns(:user)
166
- end
167
-
168
- def test_expose_a_newly_create_user_when_saved_with_success_and_role_setted
169
- @controller.class.send(:with_role, :admin)
170
- User.expects(:new).with({'these' => 'params'}, {:as => :admin}).returns(mock_user(:save => true))
171
- post :create, :user => {:these => 'params'}
172
- assert_equal mock_user, assigns(:user)
173
- @controller.class.send(:with_role, nil)
174
- end
175
-
176
- def test_expose_a_newly_create_user_when_saved_with_success_and_without_protection_setted
177
- @controller.class.send(:without_protection, true)
178
- User.expects(:new).with({'these' => 'params'}, {:without_protection => true}).returns(mock_user(:save => true))
179
- post :create, :user => {:these => 'params'}
180
- assert_equal mock_user, assigns(:user)
181
- @controller.class.send(:without_protection, nil)
182
- end
183
-
184
- def test_redirect_to_the_created_user
185
- User.stubs(:new).returns(mock_user(:save => true))
186
- @controller.expects(:resource_url).returns('http://test.host/')
187
- post :create, format: :html
188
- assert_redirected_to 'http://test.host/'
189
- end
190
-
191
- def test_show_flash_message_when_success
192
- User.stubs(:new).returns(mock_user(:save => true))
193
- post :create
194
- assert_equal flash[:notice], 'User was successfully created.'
195
- end
196
-
197
- def test_show_flash_message_with_javascript_request_when_success
198
- User.stubs(:new).returns(mock_user(:save => true))
199
- post :create, :format => :js
200
- assert_equal flash[:notice], 'User was successfully created.'
201
- end
202
-
203
- def test_render_new_template_when_user_cannot_be_saved
204
- User.stubs(:new).returns(mock_user(:save => false, :errors => {:some => :error}))
205
- post :create
206
- assert_response :success
207
- assert_equal "New HTML", @response.body.strip
208
- end
209
-
210
- def test_dont_show_flash_message_when_user_cannot_be_saved
211
- User.stubs(:new).returns(mock_user(:save => false, :errors => {:some => :error}))
212
- post :create
213
- assert flash.empty?
214
- end
215
- end
216
-
217
- class UpdateActionBaseTest < ActionController::TestCase
218
- include UserTestHelper
219
-
220
- def test_update_the_requested_object
221
- User.expects(:find).with('42').returns(mock_user)
222
- mock_user.expects(:update_attributes).with({'these' => 'params'}).returns(true)
223
- put :update, :id => '42', :user => {:these => 'params'}
224
- assert_equal mock_user, assigns(:user)
225
- end
226
-
227
- def test_update_the_requested_object_when_setted_role
228
- @controller.class.send(:with_role, :admin)
229
- User.expects(:find).with('42').returns(mock_user)
230
- mock_user.expects(:update_attributes).with({'these' => 'params'}, {:as => :admin}).returns(true)
231
- put :update, :id => '42', :user => {:these => 'params'}
232
- assert_equal mock_user, assigns(:user)
233
- @controller.class.send(:with_role, nil)
234
- end
235
-
236
- def test_update_the_requested_object_when_setted_without_protection
237
- @controller.class.send(:without_protection, true)
238
- User.expects(:find).with('42').returns(mock_user)
239
- mock_user.expects(:update_attributes).with({'these' => 'params'}, {:without_protection => true}).returns(true)
240
- put :update, :id => '42', :user => {:these => 'params'}
241
- assert_equal mock_user, assigns(:user)
242
- @controller.class.send(:without_protection, nil)
243
- end
244
-
245
- def test_redirect_to_the_updated_user
246
- User.stubs(:find).returns(mock_user(:update_attributes => true))
247
- @controller.expects(:resource_url).returns('http://test.host/')
248
- put :update
249
- assert_redirected_to 'http://test.host/'
250
- end
251
-
252
- def test_redirect_to_the_users_list_if_show_undefined
253
- @controller.class.send(:actions, :all, :except => :show)
254
- User.stubs(:find).returns(mock_user(:update_attributes => true))
255
- @controller.expects(:collection_url).returns('http://test.host/')
256
- put :update
257
- assert_redirected_to 'http://test.host/'
258
- end
259
-
260
- def test_show_flash_message_when_success
261
- User.stubs(:find).returns(mock_user(:update_attributes => true))
262
- put :update
263
- assert_equal flash[:notice], 'User was successfully updated.'
264
- end
265
-
266
- def test_show_flash_message_with_javascript_request_when_success
267
- User.stubs(:find).returns(mock_user(:update_attributes => true))
268
- post :update, :format => :js
269
- assert_equal flash[:notice], 'User was successfully updated.'
270
- end
271
-
272
- def test_render_edit_template_when_user_cannot_be_saved
273
- User.stubs(:find).returns(mock_user(:update_attributes => false, :errors => {:some => :error}))
274
- put :update
275
- assert_response :success
276
- assert_equal "Edit HTML", @response.body.strip
277
- end
278
-
279
- def test_dont_show_flash_message_when_user_cannot_be_saved
280
- User.stubs(:find).returns(mock_user(:update_attributes => false, :errors => {:some => :error}))
281
- put :update
282
- assert flash.empty?
283
- end
284
- end
285
-
286
- class DestroyActionBaseTest < ActionController::TestCase
287
- include UserTestHelper
288
-
289
- def test_the_requested_user_is_destroyed
290
- User.expects(:find).with('42').returns(mock_user)
291
- mock_user.expects(:destroy).returns(true)
292
- delete :destroy, :id => '42'
293
- assert_equal mock_user, assigns(:user)
294
- end
295
-
296
- def test_show_flash_message_when_user_can_be_deleted
297
- User.stubs(:find).returns(mock_user(:destroy => true))
298
- delete :destroy
299
- assert_equal flash[:notice], 'User was successfully destroyed.'
300
- end
301
-
302
- def test_show_flash_message_with_javascript_request_when_user_can_be_deleted
303
- User.stubs(:find).returns(mock_user(:destroy => true))
304
- delete :destroy, :format => :js
305
- assert_equal flash[:notice], 'User was successfully destroyed.'
306
- end
307
-
308
- def test_show_flash_message_when_user_cannot_be_deleted
309
- User.stubs(:find).returns(mock_user(:destroy => false, :errors => { :fail => true }))
310
- delete :destroy
311
- assert_equal flash[:alert], 'User could not be destroyed.'
312
- end
313
-
314
- def test_show_flash_message_with_javascript_request_when_user_cannot_be_deleted
315
- User.stubs(:find).returns(mock_user(:destroy => false, :errors => { :fail => true }))
316
- delete :destroy, :format => :js
317
- assert_equal flash[:alert], 'User could not be destroyed.'
318
- end
319
-
320
- def test_redirects_to_users_list
321
- User.stubs(:find).returns(mock_user(:destroy => true))
322
- @controller.expects(:collection_url).returns('http://test.host/')
323
- delete :destroy
324
- assert_redirected_to 'http://test.host/'
325
- end
326
-
327
- def test_redirects_to_the_resource_if_cannot_be_destroyed
328
- User.stubs(:find).returns(mock_user(:destroy => false))
329
- @controller.expects(:collection_url).returns('http://test.host/')
330
- delete :destroy
331
- assert_redirected_to 'http://test.host/'
332
- end
333
- end
334
-