giraffesoft-resource_controller 0.4.9 → 0.4.10

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.
Files changed (50) hide show
  1. data/README +312 -1
  2. data/lib/resource_controller.rb +10 -5
  3. data/lib/resource_controller/class_methods.rb +3 -1
  4. data/lib/resource_controller/controller.rb +6 -0
  5. data/lib/resource_controller/helpers/nested.rb +21 -3
  6. data/lib/resource_controller/helpers/singleton_customizations.rb +60 -0
  7. data/lib/resource_controller/helpers/urls.rb +5 -1
  8. data/lib/resource_controller/singleton.rb +15 -0
  9. data/lib/resource_controller/version.rb +1 -1
  10. data/lib/tasks/gem.rake +1 -1
  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/test/fixtures/images.yml +6 -0
  41. data/test/test/fixtures/users.yml +5 -0
  42. data/test/test/functional/images_controller_test.rb +37 -0
  43. data/test/test/unit/helpers/current_objects_test.rb +6 -0
  44. data/test/test/unit/helpers/nested_test.rb +5 -1
  45. data/test/test/unit/helpers/singleton_current_objects_test.rb +68 -0
  46. data/test/test/unit/helpers/singleton_nested_test.rb +77 -0
  47. data/test/test/unit/helpers/singleton_urls_test.rb +67 -0
  48. data/test/test/unit/helpers/urls_test.rb +5 -1
  49. data/test/test/unit/image_test.rb +7 -0
  50. metadata +35 -2
@@ -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: giraffesoft-resource_controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.4.10
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-03 21:00:00 -07:00
12
+ date: 2008-08-05 21:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -39,9 +39,11 @@ files:
39
39
  - lib/resource_controller/helpers/current_objects.rb
40
40
  - lib/resource_controller/helpers/internal.rb
41
41
  - lib/resource_controller/helpers/nested.rb
42
+ - lib/resource_controller/helpers/singleton_customizations.rb
42
43
  - lib/resource_controller/helpers/urls.rb
43
44
  - lib/resource_controller/helpers.rb
44
45
  - lib/resource_controller/response_collector.rb
46
+ - lib/resource_controller/singleton.rb
45
47
  - lib/resource_controller/version.rb
46
48
  - lib/resource_controller.rb
47
49
  - lib/tasks
@@ -49,11 +51,14 @@ files:
49
51
  - lib/urligence.rb
50
52
  - test/app
51
53
  - test/app/controllers
54
+ - test/app/controllers/accounts_controller.rb
52
55
  - test/app/controllers/application.rb
53
56
  - test/app/controllers/cms
54
57
  - test/app/controllers/cms/options_controller.rb
55
58
  - test/app/controllers/cms/products_controller.rb
56
59
  - test/app/controllers/comments_controller.rb
60
+ - test/app/controllers/images_controller.rb
61
+ - test/app/controllers/options_controller.rb
57
62
  - test/app/controllers/people_controller.rb
58
63
  - test/app/controllers/photos_controller.rb
59
64
  - test/app/controllers/posts_controller.rb
@@ -62,10 +67,12 @@ files:
62
67
  - test/app/controllers/tags_controller.rb
63
68
  - test/app/controllers/users_controller.rb
64
69
  - test/app/helpers
70
+ - test/app/helpers/accounts_helper.rb
65
71
  - test/app/helpers/application_helper.rb
66
72
  - test/app/helpers/cms
67
73
  - test/app/helpers/cms/products_helper.rb
68
74
  - test/app/helpers/comments_helper.rb
75
+ - test/app/helpers/images_helper.rb
69
76
  - test/app/helpers/options_helper.rb
70
77
  - test/app/helpers/people_helper.rb
71
78
  - test/app/helpers/photos_helper.rb
@@ -77,6 +84,7 @@ files:
77
84
  - test/app/models
78
85
  - test/app/models/account.rb
79
86
  - test/app/models/comment.rb
87
+ - test/app/models/image.rb
80
88
  - test/app/models/option.rb
81
89
  - test/app/models/photo.rb
82
90
  - test/app/models/post.rb
@@ -84,7 +92,13 @@ files:
84
92
  - test/app/models/project.rb
85
93
  - test/app/models/something.rb
86
94
  - test/app/models/tag.rb
95
+ - test/app/models/user.rb
87
96
  - test/app/views
97
+ - test/app/views/accounts
98
+ - test/app/views/accounts/_form.html.erb
99
+ - test/app/views/accounts/edit.html.erb
100
+ - test/app/views/accounts/new.html.erb
101
+ - test/app/views/accounts/show.html.erb
88
102
  - test/app/views/cms
89
103
  - test/app/views/cms/options
90
104
  - test/app/views/cms/options/edit.rhtml
@@ -101,6 +115,10 @@ files:
101
115
  - test/app/views/comments/index.rhtml
102
116
  - test/app/views/comments/new.rhtml
103
117
  - test/app/views/comments/show.rhtml
118
+ - test/app/views/images
119
+ - test/app/views/images/_form.html.erb
120
+ - test/app/views/images/edit.html.erb
121
+ - test/app/views/images/new.html.erb
104
122
  - test/app/views/layouts
105
123
  - test/app/views/layouts/application.rhtml
106
124
  - test/app/views/layouts/comments.rhtml
@@ -110,6 +128,12 @@ files:
110
128
  - test/app/views/layouts/projects.rhtml
111
129
  - test/app/views/layouts/somethings.rhtml
112
130
  - test/app/views/layouts/tags.rhtml
131
+ - test/app/views/options
132
+ - test/app/views/options/_form.html.erb
133
+ - test/app/views/options/edit.html.erb
134
+ - test/app/views/options/index.html.erb
135
+ - test/app/views/options/new.html.erb
136
+ - test/app/views/options/show.html.erb
113
137
  - test/app/views/people
114
138
  - test/app/views/people/edit.rhtml
115
139
  - test/app/views/people/index.rhtml
@@ -166,6 +190,8 @@ files:
166
190
  - test/db/migrate/008_create_accounts.rb
167
191
  - test/db/migrate/009_add_account_id_to_photos.rb
168
192
  - test/db/migrate/010_create_projects.rb
193
+ - test/db/migrate/011_create_images.rb
194
+ - test/db/migrate/012_create_users.rb
169
195
  - test/db/schema.rb
170
196
  - test/log
171
197
  - test/log/development.log
@@ -181,6 +207,7 @@ files:
181
207
  - test/test/fixtures
182
208
  - test/test/fixtures/accounts.yml
183
209
  - test/test/fixtures/comments.yml
210
+ - test/test/fixtures/images.yml
184
211
  - test/test/fixtures/options.yml
185
212
  - test/test/fixtures/photos.yml
186
213
  - test/test/fixtures/photos_tags.yml
@@ -189,11 +216,13 @@ files:
189
216
  - test/test/fixtures/projects.yml
190
217
  - test/test/fixtures/somethings.yml
191
218
  - test/test/fixtures/tags.yml
219
+ - test/test/fixtures/users.yml
192
220
  - test/test/functional
193
221
  - test/test/functional/cms
194
222
  - test/test/functional/cms/options_controller_test.rb
195
223
  - test/test/functional/cms/products_controller_test.rb
196
224
  - test/test/functional/comments_controller_test.rb
225
+ - test/test/functional/images_controller_test.rb
197
226
  - test/test/functional/people_controller_test.rb
198
227
  - test/test/functional/photos_controller_test.rb
199
228
  - test/test/functional/posts_controller_test.rb
@@ -213,8 +242,12 @@ files:
213
242
  - test/test/unit/helpers/current_objects_test.rb
214
243
  - test/test/unit/helpers/internal_test.rb
215
244
  - test/test/unit/helpers/nested_test.rb
245
+ - test/test/unit/helpers/singleton_current_objects_test.rb
246
+ - test/test/unit/helpers/singleton_nested_test.rb
247
+ - test/test/unit/helpers/singleton_urls_test.rb
216
248
  - test/test/unit/helpers/urls_test.rb
217
249
  - test/test/unit/helpers_test.rb
250
+ - test/test/unit/image_test.rb
218
251
  - test/test/unit/option_test.rb
219
252
  - test/test/unit/photo_test.rb
220
253
  - test/test/unit/post_test.rb