resource_controller 0.4.9 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/README.rdoc +37 -1
  2. data/Rakefile +2 -2
  3. data/lib/resource_controller.rb +10 -5
  4. data/lib/resource_controller/class_methods.rb +3 -1
  5. data/lib/resource_controller/controller.rb +6 -0
  6. data/lib/resource_controller/helpers/nested.rb +21 -3
  7. data/lib/resource_controller/helpers/singleton_customizations.rb +60 -0
  8. data/lib/resource_controller/helpers/urls.rb +5 -1
  9. data/lib/resource_controller/singleton.rb +15 -0
  10. data/lib/resource_controller/version.rb +2 -2
  11. data/test/app/controllers/accounts_controller.rb +6 -0
  12. data/test/app/controllers/cms/products_controller.rb +1 -1
  13. data/test/app/controllers/images_controller.rb +4 -0
  14. data/test/app/controllers/options_controller.rb +8 -0
  15. data/test/app/helpers/accounts_helper.rb +2 -0
  16. data/test/app/helpers/images_helper.rb +2 -0
  17. data/test/app/models/account.rb +1 -0
  18. data/test/app/models/image.rb +3 -0
  19. data/test/app/models/user.rb +3 -0
  20. data/test/app/views/accounts/_form.html.erb +4 -0
  21. data/test/app/views/accounts/edit.html.erb +14 -0
  22. data/test/app/views/accounts/new.html.erb +12 -0
  23. data/test/app/views/accounts/show.html.erb +5 -0
  24. data/test/app/views/images/_form.html.erb +4 -0
  25. data/test/app/views/images/edit.html.erb +14 -0
  26. data/test/app/views/images/new.html.erb +12 -0
  27. data/test/app/views/options/_form.html.erb +8 -0
  28. data/test/app/views/options/edit.html.erb +16 -0
  29. data/test/app/views/options/index.html.erb +21 -0
  30. data/test/app/views/options/new.html.erb +12 -0
  31. data/test/app/views/options/show.html.erb +10 -0
  32. data/test/config/database.yml +0 -3
  33. data/test/config/environment.rb +2 -2
  34. data/test/config/routes.rb +8 -1
  35. data/test/db/migrate/002_create_products.rb +1 -1
  36. data/test/db/migrate/004_create_options.rb +3 -2
  37. data/test/db/migrate/011_create_images.rb +12 -0
  38. data/test/db/migrate/012_create_users.rb +11 -0
  39. data/test/db/schema.rb +13 -6
  40. data/test/log/development.log +84 -0
  41. data/test/log/test.log +4880 -0
  42. data/test/test/fixtures/images.yml +6 -0
  43. data/test/test/fixtures/users.yml +5 -0
  44. data/test/test/functional/images_controller_test.rb +37 -0
  45. data/test/test/unit/helpers/current_objects_test.rb +6 -0
  46. data/test/test/unit/helpers/nested_test.rb +5 -1
  47. data/test/test/unit/helpers/singleton_current_objects_test.rb +68 -0
  48. data/test/test/unit/helpers/singleton_nested_test.rb +77 -0
  49. data/test/test/unit/helpers/singleton_urls_test.rb +67 -0
  50. data/test/test/unit/helpers/urls_test.rb +5 -1
  51. data/test/test/unit/image_test.rb +7 -0
  52. metadata +35 -5
  53. data/README +0 -282
  54. data/lib/tasks/gem.rake +0 -67
@@ -0,0 +1,6 @@
1
+ one:
2
+ id: 1
3
+ user_id: 1
4
+ two:
5
+ id: 2
6
+ user_id: 1
@@ -0,0 +1,5 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ one:
3
+ id: 1
4
+ two:
5
+ id: 2
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require 'images_controller'
3
+
4
+ # Re-raise errors caught by the controller.
5
+ class ImagesController; def rescue_action(e) raise e end; end
6
+
7
+ class ImagesControllerTest < Test::Unit::TestCase
8
+ def setup
9
+ @controller = ImagesController.new
10
+ @request = ActionController::TestRequest.new
11
+ @response = ActionController::TestResponse.new
12
+ @image = images :one
13
+ end
14
+
15
+ context "with user as parent" do
16
+
17
+ context "on post to :create" do
18
+ setup do
19
+ post :create, :user_id => 1, :photo => {}
20
+ end
21
+
22
+ should_redirect_to 'user_image_path(@image.user)'
23
+ should_assign_to :image
24
+ should_assign_to :user
25
+ should "scope image to user" do
26
+ assert users(:one), assigns(:image).user
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ should "not respond to show" do
33
+ assert_raise(ActionController::UnknownAction) do
34
+ get :show
35
+ end
36
+ end
37
+ end
@@ -6,6 +6,9 @@ class Helpers::CurrentObjectsTest < Test::Unit::TestCase
6
6
 
7
7
  @params = stub :[] => "1"
8
8
  @controller.stubs(:params).returns(@params)
9
+
10
+ @request = stub :path => ""
11
+ @controller.stubs(:request).returns(@request)
9
12
 
10
13
  @object = Post.new
11
14
  Post.stubs(:find).with("1").returns(@object)
@@ -113,6 +116,9 @@ class Helpers::CurrentObjectsTest < Test::Unit::TestCase
113
116
  @comment_params.stubs(:[]).with('comment').returns ""
114
117
  @comments_controller.stubs(:params).returns(@comment_params)
115
118
 
119
+ @request = stub :path => ""
120
+ @comments_controller.stubs(:request).returns(@request)
121
+
116
122
  Post.expects(:find).with(2).returns(Post.new)
117
123
  @comments = stub()
118
124
  @comments.expects(:build).with("").returns("a new comment")
@@ -19,6 +19,9 @@ class Helpers::NestedTest < Test::Unit::TestCase
19
19
 
20
20
  @params = stub :[] => "1"
21
21
  @controller.stubs(:params).returns(@params)
22
+
23
+ @request = stub :path => ""
24
+ @controller.stubs(:request).returns(@request)
22
25
 
23
26
  @object = Post.new
24
27
  Post.stubs(:find).with("1").returns(@object)
@@ -69,7 +72,8 @@ class Helpers::NestedTest < Test::Unit::TestCase
69
72
  @comments_controller = CommentsControllerMock.new
70
73
  @comment_params = stub()
71
74
  @comment_params.stubs(:[]).with(:post_id).returns 2
72
-
75
+ @request = stub :path => ""
76
+ @comments_controller.stubs(:request).returns(@request)
73
77
  @comments_controller.stubs(:params).returns(@comment_params)
74
78
  @post = Post.new
75
79
  Post.stubs(:find).with(2).returns @post
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__)+'/../../test_helper'
2
+
3
+ class Helpers::SingletonCurrentObjectsTest < Test::Unit::TestCase
4
+ context "singleton" do
5
+ setup do
6
+ @image_controller = ImagesController.new
7
+ @image_params = stub()
8
+ @image_params.stubs(:[]).with(:user_id).returns 2
9
+ @image_params.stubs(:[]).with('image').returns ""
10
+ @image_controller.stubs(:params).returns(@image_params)
11
+
12
+ @request = stub :path => ""
13
+ @image_controller.stubs(:request).returns(@request)
14
+ @user = stub()
15
+ User.expects(:find).with(2).returns(@user)
16
+ @image = stub()
17
+ end
18
+
19
+ context "build object helper with parent" do
20
+ should "build new object" do
21
+ @user.expects(:build_image).with("").returns("a new image")
22
+ assert_equal "a new image", @image_controller.send(:build_object)
23
+ end
24
+ end
25
+
26
+ context "object helper with parent" do
27
+ should "fetch the correct object" do
28
+ @user.expects(:image).returns(@image)
29
+ assert_equal @image, @image_controller.send(:object)
30
+ end
31
+ end
32
+ end
33
+
34
+ context "with singleton parent" do
35
+ setup do
36
+ @options_controller = OptionsController.new
37
+ @options_params = stub :[] => "1"
38
+ @options_params.stubs(:[]).with('option').returns ""
39
+ @options_params.stubs(:[]).with(:id).returns 1
40
+ @options_controller.stubs(:params).returns(@options_params)
41
+
42
+ @option = Option.new
43
+
44
+ @account = Account.new
45
+ @options_controller.stubs(:parent_object).returns(@account)
46
+
47
+ @request = stub :path => "account/options/1"
48
+ @options_controller.stubs(:request).returns(@request)
49
+
50
+ @options = stub()
51
+ Account.any_instance.stubs(:options).returns(@options)
52
+ end
53
+
54
+ context "build object helper" do
55
+ should "build new object" do
56
+ @options.expects(:build).with("").returns("a new option")
57
+ assert_equal "a new option", @options_controller.send(:build_object)
58
+ end
59
+ end
60
+
61
+ context "object helper" do
62
+ should "fetch the correct object" do
63
+ @options.expects(:find).with(1).returns(@option)
64
+ assert_equal @option, @options_controller.send(:object)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,77 @@
1
+ require File.dirname(__FILE__)+'/../../test_helper'
2
+
3
+ class UsersControllerMock
4
+ include ResourceController::Helpers
5
+ extend ResourceController::Accessors
6
+ class_reader_writer :belongs_to
7
+ end
8
+
9
+ class ImagesControllerMock
10
+ include ResourceController::Helpers
11
+ extend ResourceController::Accessors
12
+ include ResourceController::Helpers::SingletonCustomizations
13
+ class_reader_writer :belongs_to
14
+ belongs_to :user
15
+ end
16
+
17
+ class Helpers::SingletonNestedTest < Test::Unit::TestCase
18
+ def setup
19
+ @controller = UsersControllerMock.new
20
+ @params = stub :[] => "1"
21
+ @controller.stubs(:params).returns(@params)
22
+ @request = stub :path => ""
23
+ @controller.stubs(:request).returns(@request)
24
+ end
25
+
26
+ context "singleton parent_type helper" do
27
+ setup do
28
+ @image_controller = ImagesControllerMock.new
29
+ @image_params = stub()
30
+ @image_params.stubs(:[]).with(:user_id).returns 2
31
+ @image_controller.stubs(:params).returns(@image_params)
32
+ end
33
+
34
+ should "get the params for the current parent" do
35
+ assert_equal :user, @image_controller.send(:parent_type)
36
+ end
37
+
38
+ context "with multiple possible parents" do
39
+ setup do
40
+ ImagesControllerMock.class_eval do
41
+ belongs_to :user, :group
42
+ end
43
+ @image_params = stub()
44
+ @image_params.stubs(:[]).with(:group_id).returns 5
45
+ @image_params.stubs(:[]).with(:user_id).returns nil
46
+ @image_controller.stubs(:params).returns(@image_params)
47
+ end
48
+
49
+ should "get the params for whatever models are available" do
50
+ assert_equal :group, @image_controller.send(:parent_type)
51
+ end
52
+ end
53
+
54
+ context "with no possible parent" do
55
+ should "return nil" do
56
+ assert_nil @controller.send(:parent_type)
57
+ end
58
+ end
59
+ end
60
+
61
+ context "singleton parent_object helper" do
62
+ setup do
63
+ @image_controller = ImagesControllerMock.new
64
+ @request = stub :path => ""
65
+ @image_controller.stubs(:request).returns(@request)
66
+ @image_params = stub()
67
+ @image_params.stubs(:[]).with(:user_id).returns 2
68
+ @image_controller.stubs(:params).returns(@image_params)
69
+ @user = User.new
70
+ User.stubs(:find).with(2).returns @user
71
+ end
72
+
73
+ should "return image with id 2" do
74
+ assert_equal @user, @image_controller.send(:parent_object)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,67 @@
1
+ require File.dirname(__FILE__)+'/../../test_helper'
2
+
3
+ class Helpers::SingletonUrlsTest < Test::Unit::TestCase
4
+
5
+ context "*_url_options helpers" do
6
+ setup do
7
+ @account_controller = AccountsController.new
8
+ @params = stub :[] => ""
9
+ @account_controller.stubs(:params).returns(@params)
10
+ @request = stub :path => ""
11
+ @account_controller.stubs(:request).returns(@request)
12
+ end
13
+
14
+ should "return the correct object options" do
15
+ assert_equal [nil, nil, :account], @account_controller.send(:object_url_options)
16
+ end
17
+
18
+ context "with parent" do
19
+ setup do
20
+ @user = mock
21
+ @image = stub()
22
+ @image_controller = ImagesController.new
23
+ @image_params = stub()
24
+ @image_params.stubs(:[]).with(:user_id).returns 2
25
+ @image_controller.stubs(:params).returns(@image_params)
26
+ @image_controller.expects(:parent_object).returns @user
27
+ @image_request = stub :path => ""
28
+ @image_controller.stubs(:request).returns(@image_request)
29
+ end
30
+
31
+ should "return the correct object options" do
32
+ assert_equal [:edit, [:user, @user], :image], @image_controller.send(:object_url_options, :edit)
33
+ end
34
+ end
35
+
36
+ context "with singleton parent" do
37
+ setup do
38
+ @options_controller = OptionsController.new
39
+ @options_params = stub()
40
+ @options_params.stubs(:[]).with('option').returns ""
41
+ @options_params.stubs(:[]).with(:id).returns 1
42
+ @options_params.stubs(:[]).with(:account_id).returns nil
43
+ @options_controller.stubs(:params).returns(@options_params)
44
+
45
+ @option = Option.new
46
+
47
+ @account = Account.new
48
+ @options_controller.stubs(:parent_object).returns(@account)
49
+
50
+ @request = stub :path => "account/options/1"
51
+ @options_controller.stubs(:request).returns(@request)
52
+
53
+ @options = stub()
54
+ Account.any_instance.stubs(:options).returns(@options)
55
+ end
56
+
57
+ should "return the correct object options" do
58
+ @options.expects(:find).with(1).returns(@option)
59
+ assert_equal [:edit, :account, [:option, @option]], @options_controller.send(:object_url_options, :edit)
60
+ end
61
+
62
+ should "return the correct object options for collection" do
63
+ assert_equal [:account, :options], @options_controller.send(:collection_url_options)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -6,6 +6,9 @@ class Helpers::UrlsTest < Test::Unit::TestCase
6
6
 
7
7
  @params = stub :[] => "1"
8
8
  @controller.stubs(:params).returns(@params)
9
+
10
+ @request = stub :path => ""
11
+ @controller.stubs(:request).returns(@request)
9
12
 
10
13
  @object = Post.new
11
14
  Post.stubs(:find).with("1").returns(@object)
@@ -19,7 +22,8 @@ class Helpers::UrlsTest < Test::Unit::TestCase
19
22
  @products_controller = ::Cms::ProductsController.new
20
23
 
21
24
  @products_controller.stubs(:params).returns(@params)
22
-
25
+ @request = stub :path => ""
26
+ @products_controller.stubs(:request).returns(@request)
23
27
  @product = Product.new
24
28
  Product.stubs(:find).with("1").returns(@product)
25
29
  end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class ImageTest < Test::Unit::TestCase
4
+ def test_truth
5
+ assert true
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resource_controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Golick
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-04 00:00:00 -04:00
12
+ date: 2008-09-03 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,7 +23,6 @@ extra_rdoc_files: []
23
23
 
24
24
  files:
25
25
  - README.rdoc
26
- - README
27
26
  - LICENSE
28
27
  - init.rb
29
28
  - Rakefile
@@ -39,21 +38,24 @@ files:
39
38
  - lib/resource_controller/helpers/current_objects.rb
40
39
  - lib/resource_controller/helpers/internal.rb
41
40
  - lib/resource_controller/helpers/nested.rb
41
+ - lib/resource_controller/helpers/singleton_customizations.rb
42
42
  - lib/resource_controller/helpers/urls.rb
43
43
  - lib/resource_controller/helpers.rb
44
44
  - lib/resource_controller/response_collector.rb
45
+ - lib/resource_controller/singleton.rb
45
46
  - lib/resource_controller/version.rb
46
47
  - lib/resource_controller.rb
47
- - lib/tasks
48
- - lib/tasks/gem.rake
49
48
  - lib/urligence.rb
50
49
  - test/app
51
50
  - test/app/controllers
51
+ - test/app/controllers/accounts_controller.rb
52
52
  - test/app/controllers/application.rb
53
53
  - test/app/controllers/cms
54
54
  - test/app/controllers/cms/options_controller.rb
55
55
  - test/app/controllers/cms/products_controller.rb
56
56
  - test/app/controllers/comments_controller.rb
57
+ - test/app/controllers/images_controller.rb
58
+ - test/app/controllers/options_controller.rb
57
59
  - test/app/controllers/people_controller.rb
58
60
  - test/app/controllers/photos_controller.rb
59
61
  - test/app/controllers/posts_controller.rb
@@ -62,10 +64,12 @@ files:
62
64
  - test/app/controllers/tags_controller.rb
63
65
  - test/app/controllers/users_controller.rb
64
66
  - test/app/helpers
67
+ - test/app/helpers/accounts_helper.rb
65
68
  - test/app/helpers/application_helper.rb
66
69
  - test/app/helpers/cms
67
70
  - test/app/helpers/cms/products_helper.rb
68
71
  - test/app/helpers/comments_helper.rb
72
+ - test/app/helpers/images_helper.rb
69
73
  - test/app/helpers/options_helper.rb
70
74
  - test/app/helpers/people_helper.rb
71
75
  - test/app/helpers/photos_helper.rb
@@ -77,6 +81,7 @@ files:
77
81
  - test/app/models
78
82
  - test/app/models/account.rb
79
83
  - test/app/models/comment.rb
84
+ - test/app/models/image.rb
80
85
  - test/app/models/option.rb
81
86
  - test/app/models/photo.rb
82
87
  - test/app/models/post.rb
@@ -84,7 +89,13 @@ files:
84
89
  - test/app/models/project.rb
85
90
  - test/app/models/something.rb
86
91
  - test/app/models/tag.rb
92
+ - test/app/models/user.rb
87
93
  - test/app/views
94
+ - test/app/views/accounts
95
+ - test/app/views/accounts/_form.html.erb
96
+ - test/app/views/accounts/edit.html.erb
97
+ - test/app/views/accounts/new.html.erb
98
+ - test/app/views/accounts/show.html.erb
88
99
  - test/app/views/cms
89
100
  - test/app/views/cms/options
90
101
  - test/app/views/cms/options/edit.rhtml
@@ -101,6 +112,10 @@ files:
101
112
  - test/app/views/comments/index.rhtml
102
113
  - test/app/views/comments/new.rhtml
103
114
  - test/app/views/comments/show.rhtml
115
+ - test/app/views/images
116
+ - test/app/views/images/_form.html.erb
117
+ - test/app/views/images/edit.html.erb
118
+ - test/app/views/images/new.html.erb
104
119
  - test/app/views/layouts
105
120
  - test/app/views/layouts/application.rhtml
106
121
  - test/app/views/layouts/comments.rhtml
@@ -110,6 +125,12 @@ files:
110
125
  - test/app/views/layouts/projects.rhtml
111
126
  - test/app/views/layouts/somethings.rhtml
112
127
  - test/app/views/layouts/tags.rhtml
128
+ - test/app/views/options
129
+ - test/app/views/options/_form.html.erb
130
+ - test/app/views/options/edit.html.erb
131
+ - test/app/views/options/index.html.erb
132
+ - test/app/views/options/new.html.erb
133
+ - test/app/views/options/show.html.erb
113
134
  - test/app/views/people
114
135
  - test/app/views/people/edit.rhtml
115
136
  - test/app/views/people/index.rhtml
@@ -166,6 +187,8 @@ files:
166
187
  - test/db/migrate/008_create_accounts.rb
167
188
  - test/db/migrate/009_add_account_id_to_photos.rb
168
189
  - test/db/migrate/010_create_projects.rb
190
+ - test/db/migrate/011_create_images.rb
191
+ - test/db/migrate/012_create_users.rb
169
192
  - test/db/schema.rb
170
193
  - test/log
171
194
  - test/log/development.log
@@ -181,6 +204,7 @@ files:
181
204
  - test/test/fixtures
182
205
  - test/test/fixtures/accounts.yml
183
206
  - test/test/fixtures/comments.yml
207
+ - test/test/fixtures/images.yml
184
208
  - test/test/fixtures/options.yml
185
209
  - test/test/fixtures/photos.yml
186
210
  - test/test/fixtures/photos_tags.yml
@@ -189,11 +213,13 @@ files:
189
213
  - test/test/fixtures/projects.yml
190
214
  - test/test/fixtures/somethings.yml
191
215
  - test/test/fixtures/tags.yml
216
+ - test/test/fixtures/users.yml
192
217
  - test/test/functional
193
218
  - test/test/functional/cms
194
219
  - test/test/functional/cms/options_controller_test.rb
195
220
  - test/test/functional/cms/products_controller_test.rb
196
221
  - test/test/functional/comments_controller_test.rb
222
+ - test/test/functional/images_controller_test.rb
197
223
  - test/test/functional/people_controller_test.rb
198
224
  - test/test/functional/photos_controller_test.rb
199
225
  - test/test/functional/posts_controller_test.rb
@@ -213,8 +239,12 @@ files:
213
239
  - test/test/unit/helpers/current_objects_test.rb
214
240
  - test/test/unit/helpers/internal_test.rb
215
241
  - test/test/unit/helpers/nested_test.rb
242
+ - test/test/unit/helpers/singleton_current_objects_test.rb
243
+ - test/test/unit/helpers/singleton_nested_test.rb
244
+ - test/test/unit/helpers/singleton_urls_test.rb
216
245
  - test/test/unit/helpers/urls_test.rb
217
246
  - test/test/unit/helpers_test.rb
247
+ - test/test/unit/image_test.rb
218
248
  - test/test/unit/option_test.rb
219
249
  - test/test/unit/photo_test.rb
220
250
  - test/test/unit/post_test.rb