File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ Feature: The Hackety Blog
33 Given there is a blog post with the title "First Post"
44 When I go to the blog page
55 Then I should see "First Post"
6- Scenario : I can create a post
6+ Scenario : Admins may create a post
77 Given I'm logged in as admin
88 And I go to the new post page
99 When I fill in "Title" with "new title"
@@ -18,3 +18,11 @@ Feature: The Hackety Blog
1818 When I go to the posts page
1919 Then I should see "First Post"
2020 And I should see "Second Post"
21+ Scenario : Not logged in users cannot create a post
22+ Given I'm not logged in
23+ And I go to the new post page
24+ Then I should see "Sorry, buddy"
25+ Scenario : Non-admin users cannot create a post
26+ Given I'm logged in
27+ And I go to the new post page
28+ Then I should see "Sorry, buddy"
Original file line number Diff line number Diff line change 1- Given /^I'm logged in as admin$/ do
2- password = "foobar"
3- @user = Factory ( :admin , :password => password , :password_confirmation => password )
1+ def login user
42 visit "/login"
5- fill_in "email" , :with => @ user. email
6- fill_in "password" , :with => password
3+ fill_in "email" , :with => user . email
4+ fill_in "password" , :with => user . password
75 click_button "login"
86end
97
8+ Given /^I'm logged in as admin$/ do
9+ password = "foobar"
10+ user = Factory ( :admin , :password => password , :password_confirmation => password )
11+ login user
12+ end
13+
14+ Given /^I'm not logged in$/ do
15+ visit "/logout"
16+ end
17+
18+ Given /^I'm logged in$/ do
19+ password = "foobar"
20+ user = Factory ( :user , :password => password , :password_confirmation => password )
21+ login user
22+ end
23+
Original file line number Diff line number Diff line change 2828end
2929
3030get "/posts/new" do
31+ unless current_user . admin?
32+ flash [ :notice ] = "Sorry, buddy"
33+ redirect "/posts"
34+ end
35+
3136 haml :posts_new
3237end
3338
3439post "/posts" do
40+ unless current_user . admin?
41+ flash [ :notice ] = "Sorry, buddy"
42+ redirect "/posts"
43+ end
44+
3545 @post = Post . create ( params )
3646 flash [ :notice ] = "Post Created"
3747 redirect "/posts/#{ @post . id } "
You can’t perform that action at this time.
0 commit comments