inherited_resources 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ # Version 1.2.1
2
+
3
+ * Fix a bug with namespaces
4
+ * Use Post.scoped instead of Post.all in collection
5
+
1
6
  # Version 1.2
2
7
 
3
8
  * Improved lookup for namespaces (by github.com/Sirupsen)
data/README.rdoc CHANGED
@@ -19,7 +19,7 @@ Inherited Resources master branch is now supports Rails 3 and is NOT backward co
19
19
 
20
20
  You can let bundler to install Inherited Resources by adding this line to your application's Gemfile:
21
21
 
22
- gem 'inherited_resources', '~> 1.2'
22
+ gem 'inherited_resources', '~> 1.2.1'
23
23
 
24
24
  And then execute:
25
25
 
@@ -27,7 +27,7 @@ And then execute:
27
27
 
28
28
  Or install it yourself as:
29
29
 
30
- gem install inherited_resources --version=1.2
30
+ gem install inherited_resources --version=1.2.1
31
31
 
32
32
  === Rails 2.3.x
33
33
 
@@ -20,7 +20,7 @@ module InheritedResources
20
20
  # end
21
21
  #
22
22
  def collection
23
- get_collection_ivar || set_collection_ivar(end_of_association_chain.all)
23
+ get_collection_ivar || set_collection_ivar(end_of_association_chain.scoped)
24
24
  end
25
25
 
26
26
  # This is how the resource is loaded.
@@ -328,7 +328,7 @@ module InheritedResources
328
328
  # Forum::Thread#create will properly pick up the request parameter
329
329
  # which will be forum_thread, and not thread
330
330
  # Additionally make this work orthogonally with instance_name
331
- config[:request_name] = self.name.sub(/Controller$/, '').underscore.gsub('/', '_').singularize
331
+ config[:request_name] = self.resource_class.to_s.underscore.gsub('/', '_')
332
332
 
333
333
  # Initialize polymorphic, singleton, scopes and belongs_to parameters
334
334
  polymorphic = self.resources_configuration[:polymorphic] || { :symbols => [], :optional => false }
@@ -1,3 +1,3 @@
1
1
  module InheritedResources
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.2.1'.freeze
3
3
  end
data/test/base_test.rb CHANGED
@@ -30,33 +30,33 @@ module UserTestHelper
30
30
 
31
31
  protected
32
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
39
- end
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
40
39
  end
40
+ end
41
41
  end
42
42
 
43
43
  class IndexActionBaseTest < ActionController::TestCase
44
44
  include UserTestHelper
45
45
 
46
46
  def test_expose_all_users_as_instance_variable
47
- User.expects(:all).returns([mock_user])
47
+ User.expects(:scoped).returns([mock_user])
48
48
  get :index
49
49
  assert_equal [mock_user], assigns(:users)
50
50
  end
51
51
 
52
52
  def test_apply_scopes_if_method_is_available
53
- User.expects(:all).returns([mock_user])
53
+ User.expects(:scoped).returns([mock_user])
54
54
  get :index
55
55
  assert @controller.scopes_applied
56
56
  end
57
57
 
58
58
  def test_controller_should_render_index
59
- User.stubs(:all).returns([mock_user])
59
+ User.stubs(:scoped).returns([mock_user])
60
60
  get :index
61
61
  assert_response :success
62
62
  assert_equal 'Index HTML', @response.body.strip
@@ -64,8 +64,8 @@ class IndexActionBaseTest < ActionController::TestCase
64
64
 
65
65
  def test_render_all_users_as_xml_when_mime_type_is_xml
66
66
  @request.accept = 'application/xml'
67
- User.expects(:all).returns(mock_user)
68
- mock_user.expects(:to_xml).returns('Generated XML')
67
+ User.expects(:scoped).returns(collection = [mock_user])
68
+ collection.expects(:to_xml).returns('Generated XML')
69
69
  get :index
70
70
  assert_response :success
71
71
  assert_equal 'Generated XML', @response.body
@@ -24,7 +24,7 @@ class BelongsToTest < ActionController::TestCase
24
24
  end
25
25
 
26
26
  def test_expose_all_comments_as_instance_variable_on_index
27
- Comment.expects(:all).returns([mock_comment])
27
+ Comment.expects(:scoped).returns([mock_comment])
28
28
  get :index, :post_id => '37'
29
29
  assert_equal mock_post, assigns(:post)
30
30
  assert_equal [mock_comment], assigns(:comments)
@@ -106,7 +106,7 @@ class BelongsToTest < ActionController::TestCase
106
106
  def test_helpers
107
107
  mock_post.stubs(:class).returns(Post)
108
108
 
109
- Comment.expects(:all).returns([mock_comment])
109
+ Comment.expects(:scoped).returns([mock_comment])
110
110
  get :index, :post_id => '37'
111
111
 
112
112
  assert helper_methods.include?('parent?')
@@ -24,7 +24,7 @@ class BelongsToWithShallowTest < ActionController::TestCase
24
24
  end
25
25
 
26
26
  def test_expose_all_tags_as_instance_variable_on_index
27
- Tag.expects(:all).returns([mock_tag])
27
+ Tag.expects(:scoped).returns([mock_tag])
28
28
  get :index, :post_id => 'thirty_seven'
29
29
  assert_equal mock_post, assigns(:post)
30
30
  assert_equal [mock_tag], assigns(:tags)
@@ -22,7 +22,7 @@ class CustomizedBelongsToTest < ActionController::TestCase
22
22
  end
23
23
 
24
24
  def test_expose_the_requested_school_with_chosen_instance_variable_on_index
25
- Professor.stubs(:all).returns([mock_professor])
25
+ Professor.stubs(:scoped).returns([mock_professor])
26
26
  get :index, :school_title => 'nice'
27
27
  assert_equal mock_school, assigns(:great_school)
28
28
  end
@@ -23,7 +23,7 @@ class DefaultsTest < ActionController::TestCase
23
23
  end
24
24
 
25
25
  def test_expose_all_painters_as_instance_variable
26
- Malarz.expects(:all).returns([mock_painter])
26
+ Malarz.expects(:scoped).returns([mock_painter])
27
27
  get :index
28
28
  assert_equal [mock_painter], assigns(:malarze)
29
29
  end
@@ -90,7 +90,7 @@ class DefaultsNamespaceTest < ActionController::TestCase
90
90
  end
91
91
 
92
92
  def test_expose_all_professors_as_instance_variable
93
- Professor.expects(:all).returns([mock_professor])
93
+ Professor.expects(:scoped).returns([mock_professor])
94
94
  get :index
95
95
  assert_equal [mock_professor], assigns(:professors)
96
96
  end
@@ -116,14 +116,14 @@ class DefaultsNamespaceTest < ActionController::TestCase
116
116
 
117
117
  def test_expose_a_newly_create_professor_when_saved_with_success
118
118
  Professor.expects(:new).with({'these' => 'params'}).returns(mock_professor(:save => true))
119
- post :create, :university_professor => {:these => 'params'}
119
+ post :create, :professor => {:these => 'params'}
120
120
  assert_equal mock_professor, assigns(:professor)
121
121
  end
122
122
 
123
123
  def test_update_the_professor
124
124
  Professor.expects(:find_by_slug).with('forty_two').returns(mock_professor)
125
125
  mock_professor.expects(:update_attributes).with({'these' => 'params'}).returns(true)
126
- put :update, :id => 'forty_two', :university_professor => {:these => 'params'}
126
+ put :update, :id => 'forty_two', :professor => {:these => 'params'}
127
127
  assert_equal mock_professor, assigns(:professor)
128
128
  end
129
129
 
@@ -174,3 +174,24 @@ class TwoPartNameModelForNamespacedController < ActionController::TestCase
174
174
  assert_equal AdminRole, @controller.resource_class
175
175
  end
176
176
  end
177
+
178
+ class User
179
+ end
180
+ class Admin::UsersController < InheritedResources::Base
181
+ end
182
+ class TwoPartNameModelForNamespacedController < ActionController::TestCase
183
+ tests Admin::UsersController
184
+
185
+ def setup
186
+ # make public so we can test it
187
+ Admin::UsersController.send(:public, *Admin::UsersController.protected_instance_methods)
188
+ end
189
+
190
+ def test_that_it_picked_the_camelcased_model
191
+ assert_equal User, @controller.resource_class
192
+ end
193
+
194
+ def test_that_it_got_the_rquest_params_right
195
+ assert_equal 'user', @controller.resources_configuration[:self][:request_name]
196
+ end
197
+ end
@@ -30,7 +30,7 @@ class NestedBelongsToWithShallowTest < ActionController::TestCase
30
30
 
31
31
  def test_assigns_dresser_and_shelf_and_plate_on_index
32
32
  Shelf.expects(:find).with('37').twice.returns(mock_shelf)
33
- Plate.expects(:all).returns([mock_plate])
33
+ Plate.expects(:scoped).returns([mock_plate])
34
34
  get :index, :shelf_id => '37'
35
35
 
36
36
  assert_equal mock_dresser, assigns(:dresser)
@@ -22,14 +22,14 @@ class OptionalTest < ActionController::TestCase
22
22
  def test_expose_all_products_as_instance_variable_with_category
23
23
  Category.expects(:find).with('37').returns(mock_category)
24
24
  mock_category.expects(:products).returns(Product)
25
- Product.expects(:all).returns([mock_product])
25
+ Product.expects(:scoped).returns([mock_product])
26
26
  get :index, :category_id => '37'
27
27
  assert_equal mock_category, assigns(:category)
28
28
  assert_equal [mock_product], assigns(:products)
29
29
  end
30
30
 
31
31
  def test_expose_all_products_as_instance_variable_without_category
32
- Product.expects(:all).returns([mock_product])
32
+ Product.expects(:scoped).returns([mock_product])
33
33
  get :index
34
34
  assert_equal nil, assigns(:category)
35
35
  assert_equal [mock_product], assigns(:products)
@@ -142,7 +142,7 @@ class OptionalTest < ActionController::TestCase
142
142
  end
143
143
 
144
144
  def test_polymorphic_helpers
145
- Product.expects(:all).returns([mock_product])
145
+ Product.expects(:scoped).returns([mock_product])
146
146
  get :index
147
147
 
148
148
  assert !@controller.send(:parent?)
@@ -23,7 +23,7 @@ class PolymorphicFactoriesTest < ActionController::TestCase
23
23
  end
24
24
 
25
25
  def test_expose_all_employees_as_instance_variable_on_index
26
- Employee.expects(:all).returns([mock_employee])
26
+ Employee.expects(:scoped).returns([mock_employee])
27
27
  get :index, :factory_id => '37'
28
28
  assert_equal mock_factory, assigns(:factory)
29
29
  assert_equal [mock_employee], assigns(:employees)
@@ -77,7 +77,7 @@ class PolymorphicFactoriesTest < ActionController::TestCase
77
77
  def test_polymorphic_helpers
78
78
  mock_factory.stubs(:class).returns(Factory)
79
79
 
80
- Employee.expects(:all).returns([mock_employee])
80
+ Employee.expects(:scoped).returns([mock_employee])
81
81
  get :index, :factory_id => '37'
82
82
 
83
83
  assert @controller.send(:parent?)
@@ -110,7 +110,7 @@ class PolymorphicCompanyTest < ActionController::TestCase
110
110
  end
111
111
 
112
112
  def test_expose_all_employees_as_instance_variable_on_index
113
- Employee.expects(:all).returns([mock_employee])
113
+ Employee.expects(:scoped).returns([mock_employee])
114
114
  get :index, :company_id => '37'
115
115
  assert_equal mock_company, assigns(:company)
116
116
  assert_equal [mock_employee], assigns(:employees)
@@ -164,7 +164,7 @@ class PolymorphicCompanyTest < ActionController::TestCase
164
164
  def test_polymorphic_helpers
165
165
  mock_company.stubs(:class).returns(Company)
166
166
 
167
- Employee.expects(:all).returns([mock_employee])
167
+ Employee.expects(:scoped).returns([mock_employee])
168
168
  get :index, :company_id => '37'
169
169
 
170
170
  assert @controller.send(:parent?)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inherited_resources
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 0
10
- version: 1.2.0
9
+ - 1
10
+ version: 1.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Jos\xC3\xA9 Valim"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-25 00:00:00 +01:00
18
+ date: 2011-01-28 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency