snusnu-merb_resource_controller 0.1.0

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 (47) hide show
  1. data/LICENSE +20 -0
  2. data/README.textile +306 -0
  3. data/Rakefile +81 -0
  4. data/TODO +7 -0
  5. data/lib/merb_resource_controller/action_timeout_support.rb +53 -0
  6. data/lib/merb_resource_controller/actions.rb +169 -0
  7. data/lib/merb_resource_controller/identity_map_support.rb +20 -0
  8. data/lib/merb_resource_controller/resource_controller.rb +160 -0
  9. data/lib/merb_resource_controller/resource_proxy.rb +317 -0
  10. data/lib/merb_resource_controller.rb +29 -0
  11. data/spec/mrc_test_app/Rakefile +52 -0
  12. data/spec/mrc_test_app/app/controllers/application.rb +6 -0
  13. data/spec/mrc_test_app/app/controllers/articles.rb +3 -0
  14. data/spec/mrc_test_app/app/controllers/community/comments.rb +9 -0
  15. data/spec/mrc_test_app/app/controllers/community/ratings.rb +9 -0
  16. data/spec/mrc_test_app/app/controllers/editors.rb +7 -0
  17. data/spec/mrc_test_app/app/models/article.rb +19 -0
  18. data/spec/mrc_test_app/app/models/editor.rb +11 -0
  19. data/spec/mrc_test_app/app/views/articles/edit.html.erb +13 -0
  20. data/spec/mrc_test_app/app/views/articles/index.html.erb +25 -0
  21. data/spec/mrc_test_app/app/views/articles/new.html.erb +12 -0
  22. data/spec/mrc_test_app/app/views/articles/show.html.erb +8 -0
  23. data/spec/mrc_test_app/app/views/community/comments/edit.html.erb +12 -0
  24. data/spec/mrc_test_app/app/views/community/comments/index.html.erb +25 -0
  25. data/spec/mrc_test_app/app/views/community/comments/new.html.erb +3 -0
  26. data/spec/mrc_test_app/app/views/community/comments/show.html.erb +3 -0
  27. data/spec/mrc_test_app/app/views/community/ratings/edit.html.erb +11 -0
  28. data/spec/mrc_test_app/app/views/community/ratings/index.html.erb +25 -0
  29. data/spec/mrc_test_app/app/views/community/ratings/show.html.erb +3 -0
  30. data/spec/mrc_test_app/app/views/editors/edit.html.erb +12 -0
  31. data/spec/mrc_test_app/app/views/editors/new.html.erb +12 -0
  32. data/spec/mrc_test_app/app/views/editors/show.html.erb +7 -0
  33. data/spec/mrc_test_app/config/database.yml +33 -0
  34. data/spec/mrc_test_app/config/environments/development.rb +15 -0
  35. data/spec/mrc_test_app/config/environments/rake.rb +11 -0
  36. data/spec/mrc_test_app/config/environments/test.rb +12 -0
  37. data/spec/mrc_test_app/config/init.rb +36 -0
  38. data/spec/mrc_test_app/config/rack.rb +11 -0
  39. data/spec/mrc_test_app/config/router.rb +50 -0
  40. data/spec/mrc_test_app/spec/lib/resource_proxy_spec.rb +292 -0
  41. data/spec/mrc_test_app/spec/request/article_comments_spec.rb +208 -0
  42. data/spec/mrc_test_app/spec/request/article_editor_spec.rb +202 -0
  43. data/spec/mrc_test_app/spec/request/articles_spec.rb +208 -0
  44. data/spec/mrc_test_app/spec/request/comments_spec.rb +221 -0
  45. data/spec/mrc_test_app/spec/spec.opts +2 -0
  46. data/spec/mrc_test_app/spec/spec_helper.rb +206 -0
  47. metadata +166 -0
@@ -0,0 +1,221 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "GET" do
4
+
5
+ describe "resource(:comments)", :given => "a Comment exists" do
6
+
7
+ before(:each) do
8
+ @response = request(resource(:comments))
9
+ end
10
+
11
+ it "should respond successfully" do
12
+ @response.should be_successful
13
+ end
14
+
15
+ it "should render the :index template" do
16
+ @response.should have_selector("tr:eq(2) td:nth-child(1):contains('1')")
17
+ @response.should have_selector("tr:eq(2) td:nth-child(2):contains('article title')")
18
+ @response.should have_selector("tr:eq(2) td:nth-child(3):contains('comment body')")
19
+ @response.should_not have_selector("tr:eq(3)")
20
+ end
21
+
22
+ end
23
+
24
+ describe "resource(:comments, :new)" do
25
+
26
+ before(:each) do
27
+ @response = request(resource(:comments, :new))
28
+ end
29
+
30
+ it "should respond successfully" do
31
+ @response.should be_successful
32
+ end
33
+
34
+ it "should render the :new template" do
35
+ @response.should have_selector("h2:contains('New Comment')")
36
+ end
37
+
38
+ end
39
+
40
+ describe "resource(@comment)", :given => "a Comment exists" do
41
+
42
+ before(:each) do
43
+ @response = request(resource(Community::Comment.first))
44
+ end
45
+
46
+ it "should respond successfully" do
47
+ @response.should be_successful
48
+ end
49
+
50
+ it "should render the :show template" do
51
+ @response.should have_selector("h2:contains('Show Comment')")
52
+ @response.should have_selector("p:contains('comment body')")
53
+ end
54
+
55
+ end
56
+
57
+ describe "resource(@comment, :edit)", :given => "a Comment exists" do
58
+
59
+ before(:each) do
60
+ @response = request(resource(Community::Comment.first, :edit))
61
+ end
62
+
63
+ it "should respond successfully" do
64
+ @response.should be_successful
65
+ end
66
+
67
+ it "should render the :show template" do
68
+ @response.should have_selector("h2:contains('Edit Comment')")
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+ describe "POST resource(:comments)" do
76
+
77
+ describe "Success", :given => "an Article exists" do
78
+
79
+ before(:each) do
80
+ Community::Comment.all.destroy!
81
+ @response = request(resource(:comments),
82
+ :method => "POST",
83
+ :params => {
84
+ :comment => {
85
+ :id => nil,
86
+ :article_id => Article.first.id,
87
+ :body => "comment body"
88
+ }
89
+ }
90
+ )
91
+ end
92
+
93
+ it "should redirect to resource(@comment)" do
94
+ @response.should redirect_to(
95
+ resource(Community::Comment.first),
96
+ :message => {
97
+ :notice => "Comment was successfully created"
98
+ }
99
+ )
100
+ end
101
+
102
+ end
103
+
104
+ describe "Failure", :given => "an Article exists" do
105
+
106
+ before(:each) do
107
+ Community::Comment.all.destroy!
108
+ @response = request(
109
+ resource(:comments),
110
+ :method => "POST",
111
+ :params => {
112
+ :comment => {
113
+ :id => nil,
114
+ :article_id => nil,
115
+ :body => "comment body"
116
+ }
117
+ }
118
+ )
119
+ end
120
+
121
+ it "should not be successful" do
122
+ @response.should_not be_successful
123
+ @response.status.should == 406
124
+ end
125
+
126
+ it "should render the :new action" do
127
+ @response.should have_selector("h2:contains('New Comment')")
128
+ end
129
+
130
+ end
131
+
132
+ end
133
+
134
+ describe "PUT resource(@comment)", :given => "a Comment exists" do
135
+
136
+ describe "Success" do
137
+
138
+ before(:each) do
139
+ @comment = Community::Comment.first
140
+ @response = request(
141
+ resource(@comment),
142
+ :method => "PUT",
143
+ :params => {
144
+ :comment => {
145
+ :id => @comment.id,
146
+ :body => "updated comment body"
147
+ }
148
+ }
149
+ )
150
+ end
151
+
152
+ it "should redirect to resource(@comment)" do
153
+ @response.should redirect_to(resource(@comment))
154
+ end
155
+
156
+ end
157
+
158
+ describe "Failure" do
159
+
160
+ before(:each) do
161
+ @comment = Community::Comment.first
162
+ @response = request(
163
+ resource(@comment),
164
+ :method => "PUT",
165
+ :params => {
166
+ :comment => {
167
+ :id => @comment.id,
168
+ :article_id => nil,
169
+ :body => "updated comment body"
170
+ }
171
+ }
172
+ )
173
+ end
174
+
175
+ it "should not be successful" do
176
+ @response.should_not be_successful
177
+ @response.status.should == 406
178
+ end
179
+
180
+ it "should render the :edit template" do
181
+ @response.should have_selector("form[action='/comments/1'][method='post']")
182
+ @response.should have_selector("input[id='community::comment_body'][name='community::comment[body]'][type='text']")
183
+ @response.should have_selector("input[type='hidden'][value='put'][name='_method']")
184
+ end
185
+
186
+ end
187
+
188
+ end
189
+
190
+ describe "DELETE resource(@comment)" do
191
+
192
+ describe "Success", :given => "a Comment exists" do
193
+
194
+ before(:each) do
195
+ @response = request(
196
+ resource(Community::Comment.first),
197
+ :method => "DELETE"
198
+ )
199
+ end
200
+
201
+ it "should redirect to resource(:comments)" do
202
+ @response.should redirect_to(resource(:comments))
203
+ end
204
+
205
+ end
206
+
207
+ describe "Failure" do
208
+
209
+ before(:each) do
210
+ Community::Comment.all.destroy!
211
+ @response = request('/comments/1', :method => "DELETE")
212
+ end
213
+
214
+ it "should not be successful" do
215
+ @response.should_not be_successful
216
+ @response.status.should == 404
217
+ end
218
+
219
+ end
220
+
221
+ end
@@ -0,0 +1,2 @@
1
+ --format specdoc
2
+ --colour
@@ -0,0 +1,206 @@
1
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ require "rubygems"
4
+
5
+ # Add the local gems dir if found within the app root; any dependencies loaded
6
+ # hereafter will try to load from the local gems before loading system gems.
7
+ if (local_gem_dir = File.join(File.dirname(__FILE__), '..', 'gems')) && $BUNDLE.nil?
8
+ $BUNDLE = true; Gem.clear_paths; Gem.path.unshift(local_gem_dir)
9
+ end
10
+
11
+ require "merb-core"
12
+ require "spec" # Satisfies Autotest and anyone else not using the Rake tasks
13
+
14
+ # this loads all plugins required in your init file so don't add them
15
+ # here again, Merb will do it for you
16
+ Merb.start_environment(
17
+ :merb_root => File.join(File.dirname(__FILE__), '..'),
18
+ :environment => 'test'
19
+ )
20
+
21
+ Spec::Runner.configure do |config|
22
+ config.include Merb::Test::RequestHelper
23
+ config.include(Merb::Test::ControllerHelper)
24
+ config.include(Merb::Test::ViewHelper)
25
+ config.include(Merb::Test::RouteHelper)
26
+ end
27
+
28
+ # -----------------------------------------------------------------------------------------------
29
+ # -----------------------------------------------------------------------------------------------
30
+
31
+ given "an Article exists" do
32
+ DataMapper.auto_migrate!
33
+ request(
34
+ resource(:articles),
35
+ :method => "POST",
36
+ :params => {
37
+ :article => {
38
+ :id => nil,
39
+ :title => "article title",
40
+ :body => "article body"
41
+ }
42
+ }
43
+ )
44
+ end
45
+
46
+ given "an Editor exists" do
47
+ DataMapper.auto_migrate!
48
+ Editor.create({ :id => nil, :name => "snusnu" })
49
+ request(
50
+ resource(:articles),
51
+ :method => "POST",
52
+ :params => {
53
+ :article => {
54
+ :id => nil,
55
+ :editor_id => Editor.first.id,
56
+ :title => "article title",
57
+ :body => "article body"
58
+ }
59
+ }
60
+ )
61
+ end
62
+
63
+ given "a Comment exists" do
64
+ DataMapper.auto_migrate!
65
+ request(
66
+ resource(:articles),
67
+ :method => "POST",
68
+ :params => {
69
+ :article => {
70
+ :id => nil,
71
+ :title => "article title",
72
+ :body => "article body"
73
+ }
74
+ }
75
+ )
76
+ request(
77
+ resource(:comments),
78
+ :method => "POST",
79
+ :params => {
80
+ :comment => {
81
+ :id => nil,
82
+ :article_id => Article.first.id,
83
+ :body => "comment body"
84
+ }
85
+ }
86
+ )
87
+ end
88
+
89
+ given "a Rating exists" do
90
+ DataMapper.auto_migrate!
91
+ request(
92
+ resource(:articles),
93
+ :method => "POST",
94
+ :params => {
95
+ :article => {
96
+ :id => nil,
97
+ :title => "article title",
98
+ :body => "article body"
99
+ }
100
+ }
101
+ )
102
+ request(
103
+ resource(Article.first, :comments),
104
+ :method => "POST",
105
+ :params => {
106
+ :comment => {
107
+ :id => nil,
108
+ :body => "comment body"
109
+ }
110
+ }
111
+ )
112
+ request(
113
+ resource(Article.first, Community::Comment.first, :ratings),
114
+ :method => "POST",
115
+ :params => {
116
+ :rating => {
117
+ :id => nil,
118
+ :rate => 1
119
+ }
120
+ }
121
+ )
122
+ end
123
+
124
+ given "3 Ratings exist" do
125
+ DataMapper.auto_migrate!
126
+ request(
127
+ resource(:articles),
128
+ :method => "POST",
129
+ :params => {
130
+ :article => {
131
+ :title => "article title",
132
+ :body => "article body"
133
+ }
134
+ }
135
+ )
136
+ 2.times do
137
+ request(
138
+ resource(Article.first, :comments),
139
+ :method => "POST",
140
+ :params => {
141
+ :comment => {
142
+ :body => "comment body"
143
+ }
144
+ }
145
+ )
146
+ end
147
+ 2.times do
148
+ request(
149
+ resource(Article.first, Community::Comment.first, :ratings),
150
+ :method => "POST",
151
+ :params => {
152
+ :rating => {
153
+ :rate => 1
154
+ }
155
+ }
156
+ )
157
+ end
158
+ request(
159
+ resource(Article.first, Community::Comment.all.last, :ratings),
160
+ :method => "POST",
161
+ :params => {
162
+ :rating => {
163
+ :rate => 1
164
+ }
165
+ }
166
+ )
167
+ end
168
+
169
+ given "2 articles and 3 comments exist" do
170
+ DataMapper.auto_migrate!
171
+ 2.times do
172
+ request(
173
+ resource(:articles),
174
+ :method => "POST",
175
+ :params => {
176
+ :article => {
177
+ :id => nil,
178
+ :title => "article title",
179
+ :body => "article body"
180
+ }
181
+ }
182
+ )
183
+ end
184
+ 2.times do
185
+ request(
186
+ resource(Article.first, :comments),
187
+ :method => "POST",
188
+ :params => {
189
+ :comment => {
190
+ :id => nil,
191
+ :body => "comment body"
192
+ }
193
+ }
194
+ )
195
+ end
196
+ request(
197
+ resource(Article.all.last, :comments),
198
+ :method => "POST",
199
+ :params => {
200
+ :comment => {
201
+ :id => nil,
202
+ :body => "comment body"
203
+ }
204
+ }
205
+ )
206
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: snusnu-merb_resource_controller
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Gamsjaeger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-10 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb-core
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: "1.0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: merb-assets
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: "1.0"
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: merb-helpers
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: "1.0"
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: dm-core
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: 0.9.8
50
+ version:
51
+ - !ruby/object:Gem::Dependency
52
+ name: dm-validations
53
+ version_requirement:
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ version: 0.9.8
59
+ version:
60
+ - !ruby/object:Gem::Dependency
61
+ name: dm-serializer
62
+ version_requirement:
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 0.9.8
68
+ version:
69
+ - !ruby/object:Gem::Dependency
70
+ name: dm-constraints
71
+ version_requirement:
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 0.9.8
77
+ version:
78
+ description: A merb plugin that provides the default restful actions for controllers.
79
+ email: gamsnjaga@gmail.com
80
+ executables: []
81
+
82
+ extensions: []
83
+
84
+ extra_rdoc_files:
85
+ - LICENSE
86
+ - TODO
87
+ files:
88
+ - LICENSE
89
+ - README.textile
90
+ - Rakefile
91
+ - TODO
92
+ - lib/merb_resource_controller/action_timeout_support.rb
93
+ - lib/merb_resource_controller/actions.rb
94
+ - lib/merb_resource_controller/identity_map_support.rb
95
+ - lib/merb_resource_controller/resource_controller.rb
96
+ - lib/merb_resource_controller/resource_proxy.rb
97
+ - lib/merb_resource_controller.rb
98
+ - spec/mrc_test_app
99
+ - spec/mrc_test_app/Rakefile
100
+ - spec/mrc_test_app/app/controllers/application.rb
101
+ - spec/mrc_test_app/app/controllers/articles.rb
102
+ - spec/mrc_test_app/app/controllers/community/comments.rb
103
+ - spec/mrc_test_app/app/controllers/community/ratings.rb
104
+ - spec/mrc_test_app/app/controllers/editors.rb
105
+ - spec/mrc_test_app/app/models/article.rb
106
+ - spec/mrc_test_app/app/models/comment.rb
107
+ - spec/mrc_test_app/app/models/editor.rb
108
+ - spec/mrc_test_app/app/models/rating.rb
109
+ - spec/mrc_test_app/config/database.yml
110
+ - spec/mrc_test_app/config/environments/development.rb
111
+ - spec/mrc_test_app/config/environments/rake.rb
112
+ - spec/mrc_test_app/config/environments/test.rb
113
+ - spec/mrc_test_app/config/init.rb
114
+ - spec/mrc_test_app/config/rack.rb
115
+ - spec/mrc_test_app/config/router.rb
116
+ - spec/mrc_test_app/app/views/articles/edit.html.erb
117
+ - spec/mrc_test_app/app/views/articles/index.html.erb
118
+ - spec/mrc_test_app/app/views/articles/new.html.erb
119
+ - spec/mrc_test_app/app/views/articles/show.html.erb
120
+ - spec/mrc_test_app/app/views/community/comments/edit.html.erb
121
+ - spec/mrc_test_app/app/views/community/comments/index.html.erb
122
+ - spec/mrc_test_app/app/views/community/comments/new.html.erb
123
+ - spec/mrc_test_app/app/views/community/comments/show.html.erb
124
+ - spec/mrc_test_app/app/views/community/ratings/edit.html.erb
125
+ - spec/mrc_test_app/app/views/community/ratings/index.html.erb
126
+ - spec/mrc_test_app/app/views/community/ratings/ne.html.erb
127
+ - spec/mrc_test_app/app/views/community/ratings/show.html.erb
128
+ - spec/mrc_test_app/app/views/editors/edit.html.erb
129
+ - spec/mrc_test_app/app/views/editors/new.html.erb
130
+ - spec/mrc_test_app/app/views/editors/show.html.erb
131
+ - spec/mrc_test_app/spec/lib/resource_proxy_spec.rb
132
+ - spec/mrc_test_app/spec/request/article_comment_rtings_spec.rb
133
+ - spec/mrc_test_app/spec/request/article_comments_spec.rb
134
+ - spec/mrc_test_app/spec/request/article_editor_spec.rb
135
+ - spec/mrc_test_app/spec/request/articles_spec.rb
136
+ - spec/mrc_test_app/spec/request/comments_spec.rb
137
+ - spec/mrc_test_app/spec/spec_helper.rb
138
+ - spec/mrc_test_app/spec/spec.opts
139
+ has_rdoc: false
140
+ homepage: http://merbivore.com/
141
+ post_install_message:
142
+ rdoc_options: []
143
+
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: "0"
151
+ version:
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: "0"
157
+ version:
158
+ requirements: []
159
+
160
+ rubyforge_project: merb_resource_controller
161
+ rubygems_version: 1.2.0
162
+ signing_key:
163
+ specification_version: 2
164
+ summary: A merb plugin that provides the default restful actions for controllers.
165
+ test_files: []
166
+