bumble 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +16 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/Readme.mdown +8 -0
- data/app/controllers/bumble_controller.rb +45 -0
- data/app/controllers/comments_controller.rb +99 -0
- data/app/controllers/password_resets_controller.rb +34 -0
- data/app/controllers/posts_controller.rb +103 -0
- data/app/controllers/user_sessions_controller.rb +22 -0
- data/app/controllers/users_controller.rb +60 -0
- data/app/helpers/bumble_helper.rb +50 -0
- data/app/models/asset.rb +57 -0
- data/app/models/comment.rb +78 -0
- data/app/models/notifier.rb +35 -0
- data/app/models/post.rb +57 -0
- data/app/models/posts/blog.rb +3 -0
- data/app/models/posts/code.rb +3 -0
- data/app/models/posts/image.rb +3 -0
- data/app/models/posts/link.rb +7 -0
- data/app/models/posts/quote.rb +3 -0
- data/app/models/posts/video.rb +4 -0
- data/app/models/user.rb +35 -0
- data/app/models/user_session.rb +2 -0
- data/app/views/comments/_comment.html.haml +14 -0
- data/app/views/comments/_form.html.haml +9 -0
- data/app/views/comments/edit.html.haml +7 -0
- data/app/views/comments/index.atom.builder +15 -0
- data/app/views/comments/new.html.haml +7 -0
- data/app/views/layouts/_sidebar.html.haml +20 -0
- data/app/views/layouts/bumble.html.haml +35 -0
- data/app/views/notifier/activation_confirmation.erb +5 -0
- data/app/views/notifier/activation_instructions.erb +5 -0
- data/app/views/notifier/new_comment_alert.erb +8 -0
- data/app/views/notifier/password_reset_instructions.erb +8 -0
- data/app/views/password_resets/edit.html.haml +10 -0
- data/app/views/password_resets/new.html.haml +7 -0
- data/app/views/posts/_form.html.haml +10 -0
- data/app/views/posts/_post.html.haml +16 -0
- data/app/views/posts/_preview.html.haml +8 -0
- data/app/views/posts/edit.html.haml +10 -0
- data/app/views/posts/forms/_blog.html.haml +4 -0
- data/app/views/posts/forms/_code.html.haml +6 -0
- data/app/views/posts/forms/_image.html.haml +9 -0
- data/app/views/posts/forms/_link.html.haml +6 -0
- data/app/views/posts/forms/_quote.html.haml +4 -0
- data/app/views/posts/forms/_video.html.haml +6 -0
- data/app/views/posts/index.atom.builder +15 -0
- data/app/views/posts/index.html.haml +21 -0
- data/app/views/posts/new.html.haml +8 -0
- data/app/views/posts/search.html.haml +27 -0
- data/app/views/posts/show.html.haml +22 -0
- data/app/views/posts/types/_blog.html.haml +4 -0
- data/app/views/posts/types/_code.html.haml +7 -0
- data/app/views/posts/types/_image.html.haml +3 -0
- data/app/views/posts/types/_link.html.haml +3 -0
- data/app/views/posts/types/_quote.html.haml +2 -0
- data/app/views/posts/types/_video.html.haml +5 -0
- data/app/views/user_sessions/new.html.haml +10 -0
- data/app/views/users/_form.html.haml +12 -0
- data/app/views/users/_user.html.haml +3 -0
- data/app/views/users/delete.html.haml +5 -0
- data/app/views/users/edit.html.haml +8 -0
- data/app/views/users/index.html.haml +3 -0
- data/app/views/users/new.html.haml +7 -0
- data/app/views/users/show.html.haml +6 -0
- data/bumble.gemspec +31 -0
- data/config/initializers/bumble.rb +9 -0
- data/config/initializers/haml.rb +2 -0
- data/config/initializers/html5_forms.rb +163 -0
- data/config/initializers/inflections.rb +10 -0
- data/config/initializers/mime_types.rb +5 -0
- data/config/initializers/will_paginate.rb +3 -0
- data/config/routes.rb +29 -0
- data/lib/bumble.rb +18 -0
- data/lib/bumble/version.rb +3 -0
- data/lib/generators/bumble/assets_generator.rb +10 -0
- data/lib/generators/bumble/migrations_generator.rb +40 -0
- data/lib/generators/bumble/templates/assets/images/.gitignore +0 -0
- data/lib/generators/bumble/templates/assets/images/close.png +0 -0
- data/lib/generators/bumble/templates/assets/images/email.png +0 -0
- data/lib/generators/bumble/templates/assets/images/feed.png +0 -0
- data/lib/generators/bumble/templates/assets/images/image.png +0 -0
- data/lib/generators/bumble/templates/assets/images/loading.gif +0 -0
- data/lib/generators/bumble/templates/assets/images/preview.png +0 -0
- data/lib/generators/bumble/templates/assets/images/shortcut.png +0 -0
- data/lib/generators/bumble/templates/assets/images/youtube.png +0 -0
- data/lib/generators/bumble/templates/assets/javascripts/admin.js +95 -0
- data/lib/generators/bumble/templates/assets/javascripts/bumble.js +76 -0
- data/lib/generators/bumble/templates/assets/javascripts/iphone.js +7 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.autogrow.js +37 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.cookie.js +96 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.form.js +665 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.hint.js +44 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.jgrow.js +85 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.js +154 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.ui.core.js +18 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.ui.tabs.js +13 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.ui.widget.js +18 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.validate.js +16 -0
- data/lib/generators/bumble/templates/assets/javascripts/modernizr.js +13 -0
- data/lib/generators/bumble/templates/assets/javascripts/ui.core.js +289 -0
- data/lib/generators/bumble/templates/assets/javascripts/ui.tabs.js +593 -0
- data/lib/generators/bumble/templates/migrations/add_approved_to_comments.rb +15 -0
- data/lib/generators/bumble/templates/migrations/add_delta_to_posts.rb +9 -0
- data/lib/generators/bumble/templates/migrations/add_missing_indexes.rb +24 -0
- data/lib/generators/bumble/templates/migrations/add_url_to_users.rb +9 -0
- data/lib/generators/bumble/templates/migrations/create_assets.rb +18 -0
- data/lib/generators/bumble/templates/migrations/create_comments.rb +19 -0
- data/lib/generators/bumble/templates/migrations/create_posts.rb +25 -0
- data/lib/generators/bumble/templates/migrations/create_users.rb +28 -0
- data/lib/generators/bumble/templates/migrations/full_text_search.rb +13 -0
- data/public/stylesheets/sass/bumble.sass +423 -0
- data/public/stylesheets/sass/iphone.sass +79 -0
- data/public/stylesheets/sass/print.sass +2 -0
- data/public/stylesheets/sass/reset.sass +49 -0
- data/test/factories.rb +28 -0
- data/test/functional/comments_controller_test.rb +177 -0
- data/test/functional/password_resets_controller_test.rb +61 -0
- data/test/functional/posts_controller_test.rb +181 -0
- data/test/test_helper.rb +113 -0
- data/test/unit/comment_test.rb +18 -0
- data/test/unit/post_test.rb +18 -0
- data/test/unit/user_test.rb +37 -0
- metadata +403 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
@import reset.sass
|
2
|
+
|
3
|
+
body
|
4
|
+
:width auto
|
5
|
+
:padding 10px
|
6
|
+
#header
|
7
|
+
:height auto
|
8
|
+
:padding 10px 0
|
9
|
+
h1
|
10
|
+
:margin-left 0px
|
11
|
+
|
12
|
+
.field
|
13
|
+
input[type='text'], input[type='search'], input[type='password'], textarea
|
14
|
+
:padding 4px 3px
|
15
|
+
:-webkit-appearance textfield
|
16
|
+
|
17
|
+
#content
|
18
|
+
:width 100%
|
19
|
+
.flash
|
20
|
+
:position static
|
21
|
+
:margin-top 0
|
22
|
+
label.error
|
23
|
+
:margin -5px 0 0
|
24
|
+
:right 5px
|
25
|
+
#search
|
26
|
+
.meta
|
27
|
+
:float none
|
28
|
+
.open
|
29
|
+
:right 15px
|
30
|
+
:margin 0
|
31
|
+
#new_post
|
32
|
+
ul
|
33
|
+
li
|
34
|
+
:font-size 0.9em
|
35
|
+
:padding 2px 4px
|
36
|
+
.close
|
37
|
+
:position absolute
|
38
|
+
:margin -10px 0 0
|
39
|
+
:right 0
|
40
|
+
#posts
|
41
|
+
.post
|
42
|
+
:margin-bottom 20px
|
43
|
+
.post
|
44
|
+
:overflow scroll
|
45
|
+
h2
|
46
|
+
:margin-bottom 5px
|
47
|
+
.meta
|
48
|
+
:font-size 11px
|
49
|
+
img
|
50
|
+
:max-width 100%
|
51
|
+
object, embed
|
52
|
+
:width 100% !important
|
53
|
+
.pagination
|
54
|
+
:padding-top 0
|
55
|
+
#sidebar
|
56
|
+
:width 100%
|
57
|
+
:margin 0
|
58
|
+
:position static
|
59
|
+
#search_form
|
60
|
+
.field
|
61
|
+
:display inline
|
62
|
+
input
|
63
|
+
:width 69%
|
64
|
+
h3
|
65
|
+
:padding 20px 0 0
|
66
|
+
:margin 0 0 12px
|
67
|
+
ul#links
|
68
|
+
:padding-bottom 0px
|
69
|
+
li
|
70
|
+
:margin-bottom 10px
|
71
|
+
:width 120px
|
72
|
+
:float left
|
73
|
+
#footer
|
74
|
+
:clear both
|
75
|
+
:padding-top 15px
|
76
|
+
|
77
|
+
html.flip
|
78
|
+
object, embed
|
79
|
+
display: none
|
@@ -0,0 +1,49 @@
|
|
1
|
+
/* http://meyerweb.com/eric/tools/css/reset/
|
2
|
+
/* v1.0 | 20080212
|
3
|
+
|
4
|
+
html, body, div, span, applet, object, iframe,
|
5
|
+
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
6
|
+
a, abbr, acronym, address, big, cite, code,
|
7
|
+
del, dfn, em, font, img, ins, kbd, q, s, samp,
|
8
|
+
small, strike, strong, sub, sup, tt, var,
|
9
|
+
b, u, i, center,
|
10
|
+
dl, dt, dd, ol, ul, li,
|
11
|
+
fieldset, form, label, legend,
|
12
|
+
table, caption, tbody, tfoot, thead, tr, th, td
|
13
|
+
:margin 0
|
14
|
+
:padding 0
|
15
|
+
:border 0
|
16
|
+
:outline 0
|
17
|
+
:font-size 100%
|
18
|
+
:vertical-align baseline
|
19
|
+
:background transparent
|
20
|
+
|
21
|
+
body
|
22
|
+
:line-height 1
|
23
|
+
|
24
|
+
ol, ul
|
25
|
+
:list-style none
|
26
|
+
|
27
|
+
blockquote, q
|
28
|
+
:quotes none
|
29
|
+
|
30
|
+
blockquote:before, blockquote:after,
|
31
|
+
q:before, q:after
|
32
|
+
:content ''
|
33
|
+
:content none
|
34
|
+
|
35
|
+
/* remember to define focus styles!
|
36
|
+
*:focus
|
37
|
+
:outline 0
|
38
|
+
|
39
|
+
/* remember to highlight inserts somehow!
|
40
|
+
ins
|
41
|
+
:text-decoration none
|
42
|
+
|
43
|
+
del
|
44
|
+
:text-decoration line-through
|
45
|
+
|
46
|
+
/* tables still need 'cellspacing="0"' in the markup
|
47
|
+
table
|
48
|
+
:border-collapse collapse
|
49
|
+
:border-spacing 0
|
data/test/factories.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Factory.define :user do |f|
|
2
|
+
f.sequence(:email) {|n| "person#{n}@something.co.uk" }
|
3
|
+
f.password 'password'
|
4
|
+
f.first_name 'Andrew'
|
5
|
+
f.password_confirmation { |u| u.password }
|
6
|
+
end
|
7
|
+
|
8
|
+
Factory.define :post do |f|
|
9
|
+
f.title 'Hello world!'
|
10
|
+
f.description 'content'
|
11
|
+
f.association(:user)
|
12
|
+
f.published_at 1.week.ago
|
13
|
+
f.publicly_viewable true
|
14
|
+
end
|
15
|
+
|
16
|
+
Factory.define :blog do |f|
|
17
|
+
f.title 'Hello world!'
|
18
|
+
f.description 'content'
|
19
|
+
f.association(:user)
|
20
|
+
f.published_at 1.week.ago
|
21
|
+
f.publicly_viewable true
|
22
|
+
end
|
23
|
+
|
24
|
+
Factory.define :comment do |f|
|
25
|
+
f.body 'I love this!'
|
26
|
+
f.association(:user)
|
27
|
+
f.post {|post| post.association(:blog) }
|
28
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class CommentsControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@comment = Factory.create(:comment)
|
7
|
+
end
|
8
|
+
|
9
|
+
should_route :get, "posts/1/comments", :post_id => '1', :controller => :comments, :action => :index
|
10
|
+
should_route :get, "posts/1/comments/new", :post_id => '1', :action => :new
|
11
|
+
should_route :post, "posts/1/comments", :post_id => '1', :action => :create
|
12
|
+
should_route :get, "posts/1/comments/1", :post_id => '1', :action => :show, :id => '1'
|
13
|
+
should_route :get, "posts/1/comments/1/edit", :post_id => '1', :action => :edit, :id => '1'
|
14
|
+
should_route :put, "posts/1/comments/1", :post_id => '1', :action => :update, :id => '1'
|
15
|
+
should_route :delete, "posts/1/comments/1", :post_id => '1', :action => :destroy, :id => '1'
|
16
|
+
|
17
|
+
context "logged in" do
|
18
|
+
setup do
|
19
|
+
activate_authlogic
|
20
|
+
UserSession.create(Factory.create(:user))
|
21
|
+
end
|
22
|
+
|
23
|
+
context "on GET to :show for first record" do
|
24
|
+
setup do
|
25
|
+
get :show, :id => @comment.id, :post_id => @comment.post.id
|
26
|
+
end
|
27
|
+
|
28
|
+
should_redirect_to('the comments post') { post_url(@comment.post.to_param, :anchor => dom_id(@comment))}
|
29
|
+
should_not_set_the_flash
|
30
|
+
end
|
31
|
+
|
32
|
+
context "on GET to :new" do
|
33
|
+
setup do
|
34
|
+
get :new, :post_id => @comment.post.id
|
35
|
+
end
|
36
|
+
|
37
|
+
should_assign_to :comment
|
38
|
+
should_respond_with :success
|
39
|
+
should_render_template :new
|
40
|
+
should_not_set_the_flash
|
41
|
+
end
|
42
|
+
|
43
|
+
context "on GET to :index" do
|
44
|
+
setup do
|
45
|
+
get :index, :post_id => @comment.post.to_param
|
46
|
+
end
|
47
|
+
|
48
|
+
should_redirect_to('the comments post') { post_url(@comment.post.to_param, :anchor => 'comments')}
|
49
|
+
should_not_set_the_flash
|
50
|
+
end
|
51
|
+
|
52
|
+
context "on POST to :create" do
|
53
|
+
setup do
|
54
|
+
@old_count = Comment.count
|
55
|
+
post :create, :comment => Factory.attributes_for(:comment), :post_id => @comment.post.id
|
56
|
+
end
|
57
|
+
|
58
|
+
should "create a new comment" do
|
59
|
+
assert_equal @old_count + 1, Comment.count
|
60
|
+
end
|
61
|
+
|
62
|
+
should_assign_to :comment
|
63
|
+
should_set_the_flash_to 'Create successful!'
|
64
|
+
should_redirect_to('the comments post') { post_url(@comment.post.to_param, :anchor => dom_id(assigns(:comment)))}
|
65
|
+
end
|
66
|
+
|
67
|
+
context "on GET to :edit for first record" do
|
68
|
+
setup do
|
69
|
+
get :edit, :id => @comment.id, :post_id => @comment.post.id
|
70
|
+
end
|
71
|
+
|
72
|
+
should_assign_to :comment
|
73
|
+
should_respond_with :success
|
74
|
+
should_render_template :edit
|
75
|
+
should_not_set_the_flash
|
76
|
+
end
|
77
|
+
|
78
|
+
context "on PUT to :update" do
|
79
|
+
setup do
|
80
|
+
put :update, :id => @comment.id, :post_id => @comment.post.id, :comment => {}
|
81
|
+
end
|
82
|
+
|
83
|
+
should_assign_to :comment
|
84
|
+
should_set_the_flash_to 'Save successful!'
|
85
|
+
should_redirect_to('the comments post') { post_url(@comment.post.to_param, :anchor => dom_id(@comment))}
|
86
|
+
end
|
87
|
+
|
88
|
+
context "on DELETE to :destroy" do
|
89
|
+
setup do
|
90
|
+
@old_count = Comment.count
|
91
|
+
delete :destroy, :id => @comment.id, :post_id => @comment.post.id
|
92
|
+
end
|
93
|
+
|
94
|
+
should "destroy comment" do
|
95
|
+
assert_equal @old_count - 1, Comment.count
|
96
|
+
end
|
97
|
+
|
98
|
+
should_set_the_flash_to 'Record deleted!'
|
99
|
+
should_redirect_to('the comments post') { post_url(@comment.post.to_param)}
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "not logged in" do
|
104
|
+
context "on GET to :show for first record" do
|
105
|
+
setup do
|
106
|
+
get :show, :id => @comment.id, :post_id => @comment.post.id
|
107
|
+
end
|
108
|
+
|
109
|
+
should_redirect_to('the comments post') { post_url(@comment.post.to_param, :anchor => dom_id(@comment))}
|
110
|
+
should_not_set_the_flash
|
111
|
+
end
|
112
|
+
|
113
|
+
context "on GET to :new" do
|
114
|
+
setup do
|
115
|
+
get :new, :post_id => @comment.post.id
|
116
|
+
end
|
117
|
+
|
118
|
+
should_assign_to :comment
|
119
|
+
should_respond_with :success
|
120
|
+
should_render_template :new
|
121
|
+
should_not_set_the_flash
|
122
|
+
end
|
123
|
+
|
124
|
+
context "on GET to :index" do
|
125
|
+
setup do
|
126
|
+
get :index, :post_id => @comment.post.id
|
127
|
+
end
|
128
|
+
|
129
|
+
should_redirect_to('the comments post') { post_url(@comment.post.to_param, :anchor => 'comments')}
|
130
|
+
should_not_set_the_flash
|
131
|
+
end
|
132
|
+
|
133
|
+
context "on POST to :create" do
|
134
|
+
setup do
|
135
|
+
@old_count = Comment.count
|
136
|
+
post :create, :comment => Factory.attributes_for(:comment, :author_name => 'David', :author_email => 'dave@example.com'), :post_id => @comment.post.id
|
137
|
+
end
|
138
|
+
|
139
|
+
should "create a new comment" do
|
140
|
+
assert_equal @old_count + 1, Comment.count
|
141
|
+
end
|
142
|
+
|
143
|
+
should_assign_to :comment
|
144
|
+
should_set_the_flash_to 'Create successful!'
|
145
|
+
should_redirect_to('the comments post') { post_url(@comment.post.to_param, :anchor => dom_id(assigns(:comment)))}
|
146
|
+
end
|
147
|
+
|
148
|
+
context "on GET to :edit for first record" do
|
149
|
+
setup do
|
150
|
+
get :edit, :id => @comment.id, :post_id => @comment.post.id
|
151
|
+
end
|
152
|
+
|
153
|
+
should_be_denied_access
|
154
|
+
end
|
155
|
+
|
156
|
+
context "on PUT to :update" do
|
157
|
+
setup do
|
158
|
+
put :update, :id => @comment.id, :post_id => @comment.post.id, :comment => {}
|
159
|
+
end
|
160
|
+
|
161
|
+
should_be_denied_access
|
162
|
+
end
|
163
|
+
|
164
|
+
context "on DELETE to :destroy" do
|
165
|
+
setup do
|
166
|
+
@old_count = Comment.count
|
167
|
+
delete :destroy, :id => @comment.id, :post_id => @comment.post.id
|
168
|
+
end
|
169
|
+
|
170
|
+
should "not destroy comment" do
|
171
|
+
assert_equal @old_count, Comment.count
|
172
|
+
end
|
173
|
+
|
174
|
+
should_be_denied_access
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class PasswordResetsControllerTest < ActionController::TestCase
|
4
|
+
def setup
|
5
|
+
@user = Factory.create(:user)
|
6
|
+
end
|
7
|
+
|
8
|
+
should_route :get, "/password_resets", :controller => :password_resets, :action => :index
|
9
|
+
should_route :get, "/password_resets/new", :action => :new
|
10
|
+
should_route :post, "/password_resets", :action => :create
|
11
|
+
should_route :get, "/password_resets/1234567abcdefg/edit", :action => :edit, :id => '1234567abcdefg'
|
12
|
+
should_route :put, "/password_resets/1234567abcdefg", :action => :update, :id => '1234567abcdefg'
|
13
|
+
|
14
|
+
context "on GET to :new" do
|
15
|
+
setup do
|
16
|
+
get :new
|
17
|
+
end
|
18
|
+
|
19
|
+
should_respond_with :success
|
20
|
+
should_render_template :new
|
21
|
+
should_not_set_the_flash
|
22
|
+
end
|
23
|
+
|
24
|
+
context "on POST to :create" do
|
25
|
+
setup do
|
26
|
+
post :create, :email => @user.email
|
27
|
+
end
|
28
|
+
|
29
|
+
should_assign_to :user
|
30
|
+
should_set_the_flash_to "Instructions to reset your password have been emailed to you. Please check your email."
|
31
|
+
should_redirect_to('the created password_reset') { root_url}
|
32
|
+
end
|
33
|
+
|
34
|
+
context "a user who has requested a password reset" do
|
35
|
+
setup do
|
36
|
+
@user = Factory.create(:user)
|
37
|
+
@user.deliver_password_reset_instructions!
|
38
|
+
end
|
39
|
+
|
40
|
+
context "on GET to :edit for first record" do
|
41
|
+
setup do
|
42
|
+
get :edit, :id => @user.perishable_token
|
43
|
+
end
|
44
|
+
|
45
|
+
should_assign_to :user
|
46
|
+
should_respond_with :success
|
47
|
+
should_render_template :edit
|
48
|
+
should_not_set_the_flash
|
49
|
+
end
|
50
|
+
|
51
|
+
context "on PUT to :update" do
|
52
|
+
setup do
|
53
|
+
put :update, :id => @user.perishable_token, :user => {}
|
54
|
+
end
|
55
|
+
|
56
|
+
should_assign_to :user
|
57
|
+
should_set_the_flash_to "Password successfully updated"
|
58
|
+
should_redirect_to('the updated password_reset') { root_path}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class PostsControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@post = Factory.create(:blog)
|
7
|
+
end
|
8
|
+
|
9
|
+
should_route :get, "/posts", :controller => :posts, :action => :index
|
10
|
+
should_route :get, "/posts/new", :action => :new
|
11
|
+
should_route :post, "/posts", :action => :create
|
12
|
+
should_route :get, "/posts/1", :action => :show, :id => '1'
|
13
|
+
should_route :get, "/posts/1/edit", :action => :edit, :id => '1'
|
14
|
+
should_route :put, "/posts/1", :action => :update, :id => '1'
|
15
|
+
should_route :delete, "/posts/1", :action => :destroy, :id => '1'
|
16
|
+
|
17
|
+
context "not logged in" do
|
18
|
+
|
19
|
+
context "on GET to :show for first record" do
|
20
|
+
setup do
|
21
|
+
get :show, :id => @post.id
|
22
|
+
end
|
23
|
+
|
24
|
+
should_assign_to :post
|
25
|
+
should_respond_with :success
|
26
|
+
should_render_template :show
|
27
|
+
should_not_set_the_flash
|
28
|
+
end
|
29
|
+
|
30
|
+
context "on GET to :new" do
|
31
|
+
setup do
|
32
|
+
get :new
|
33
|
+
end
|
34
|
+
|
35
|
+
should_be_denied_access
|
36
|
+
end
|
37
|
+
|
38
|
+
context "on GET to :index" do
|
39
|
+
setup do
|
40
|
+
get :index
|
41
|
+
end
|
42
|
+
|
43
|
+
should_assign_to :posts
|
44
|
+
should_respond_with :success
|
45
|
+
should_render_template :index
|
46
|
+
should_not_set_the_flash
|
47
|
+
end
|
48
|
+
|
49
|
+
context "on POST to :create" do
|
50
|
+
setup do
|
51
|
+
@old_count = Post.count
|
52
|
+
post :create, :post => Factory.attributes_for(:blog, :title => 'Testing')
|
53
|
+
end
|
54
|
+
|
55
|
+
should "not create a new post" do
|
56
|
+
assert_equal @old_count, Post.count
|
57
|
+
end
|
58
|
+
|
59
|
+
should_be_denied_access
|
60
|
+
end
|
61
|
+
|
62
|
+
context "on GET to :edit for first record" do
|
63
|
+
setup do
|
64
|
+
get :edit, :id => @post.id
|
65
|
+
end
|
66
|
+
|
67
|
+
should_be_denied_access
|
68
|
+
end
|
69
|
+
|
70
|
+
context "on PUT to :update" do
|
71
|
+
setup do
|
72
|
+
put :update, :id => @post.id, :post => Factory.attributes_for(:blog, :title => 'Testing')
|
73
|
+
end
|
74
|
+
|
75
|
+
should_be_denied_access
|
76
|
+
end
|
77
|
+
|
78
|
+
context "on DELETE to :destroy" do
|
79
|
+
setup do
|
80
|
+
@old_count = Post.count
|
81
|
+
delete :destroy, :id => @post.id
|
82
|
+
end
|
83
|
+
|
84
|
+
should "not destroy post" do
|
85
|
+
assert_equal @old_count, Post.count
|
86
|
+
end
|
87
|
+
|
88
|
+
should_be_denied_access
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "logged in" do
|
93
|
+
setup do
|
94
|
+
activate_authlogic
|
95
|
+
UserSession.create(Factory.create(:user))
|
96
|
+
end
|
97
|
+
|
98
|
+
context "on GET to :show for first record" do
|
99
|
+
setup do
|
100
|
+
get :show, :id => @post.id
|
101
|
+
end
|
102
|
+
|
103
|
+
should_assign_to :post
|
104
|
+
should_respond_with :success
|
105
|
+
should_render_template :show
|
106
|
+
should_not_set_the_flash
|
107
|
+
end
|
108
|
+
|
109
|
+
context "on GET to :new" do
|
110
|
+
setup do
|
111
|
+
get :new
|
112
|
+
end
|
113
|
+
|
114
|
+
should_assign_to :post
|
115
|
+
should_respond_with :success
|
116
|
+
should_render_template :new
|
117
|
+
should_not_set_the_flash
|
118
|
+
end
|
119
|
+
|
120
|
+
context "on GET to :index" do
|
121
|
+
setup do
|
122
|
+
get :index
|
123
|
+
end
|
124
|
+
|
125
|
+
should_assign_to :posts
|
126
|
+
should_respond_with :success
|
127
|
+
should_render_template :index
|
128
|
+
should_not_set_the_flash
|
129
|
+
end
|
130
|
+
|
131
|
+
context "on POST to :create" do
|
132
|
+
setup do
|
133
|
+
@old_count = Post.count
|
134
|
+
post :create, :blog => Factory.attributes_for(:blog, :title => 'Testing')
|
135
|
+
end
|
136
|
+
|
137
|
+
should "create a new post" do
|
138
|
+
assert_equal @old_count + 1, Post.count
|
139
|
+
end
|
140
|
+
|
141
|
+
should_assign_to :post
|
142
|
+
should_set_the_flash_to 'Create successful!'
|
143
|
+
should_redirect_to('the created post') { post_url('testing')}
|
144
|
+
end
|
145
|
+
|
146
|
+
context "on GET to :edit for first record" do
|
147
|
+
setup do
|
148
|
+
get :edit, :id => @post.id
|
149
|
+
end
|
150
|
+
|
151
|
+
should_assign_to :post
|
152
|
+
should_respond_with :success
|
153
|
+
should_render_template :edit
|
154
|
+
should_not_set_the_flash
|
155
|
+
end
|
156
|
+
|
157
|
+
context "on PUT to :update" do
|
158
|
+
setup do
|
159
|
+
put :update, :id => @post.id, :post => {}
|
160
|
+
end
|
161
|
+
|
162
|
+
should_assign_to :post
|
163
|
+
should_set_the_flash_to 'Save successful!'
|
164
|
+
should_redirect_to('the updated post') { post_url(@post)}
|
165
|
+
end
|
166
|
+
|
167
|
+
context "on DELETE to :destroy" do
|
168
|
+
setup do
|
169
|
+
@old_count = Post.count
|
170
|
+
delete :destroy, :id => @post.id
|
171
|
+
end
|
172
|
+
|
173
|
+
should "destroy post" do
|
174
|
+
assert_equal @old_count - 1, Post.count
|
175
|
+
end
|
176
|
+
|
177
|
+
should_set_the_flash_to 'Record deleted!'
|
178
|
+
should_redirect_to('list of posts') { posts_url }
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|