Skip to content

Commit cf442d3

Browse files
committed
User model spec
1 parent 9930b0f commit cf442d3

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

features/step_definitions/user_steps.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
def login_user
2-
@user = User.create!(username: "test_user",
2+
@user = User.create!(username: "test_user",
33
email: "test_user@example.com",
44
password: "foobar",
55
password_confirmation: "foobar")
@@ -20,6 +20,13 @@ def create_other_user
2020
login_user unless @user
2121
end
2222

23+
Given /^a steve exists$/ do
24+
@steve = User.create!(username: "steve",
25+
email: "steve_user@example.com",
26+
password: "foobar",
27+
password_confirmation: "foobar")
28+
end
29+
2330
When /^I go to look at my profile page$/ do
2431
visit user_path(@user)
2532
end
@@ -73,3 +80,7 @@ def create_other_user
7380
page.should have_content("Test user likes to edit his profile")
7481
end
7582

83+
Then(/^I should see 'Steve'$/) do
84+
@user.following?(@steve).should == true
85+
page.should have_link @steve.username
86+
end

features/users.feature

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Feature: Manage account
33
As a user of this site, I can view and update my profile, see my followers
44

55
Background:
6-
Given a logged in user
6+
Given a steve exists
7+
And a logged in user
78

89
Scenario: View my profile
910
When I go to look at my profile page
@@ -23,4 +24,7 @@ Feature: Manage account
2324
When I am following someone
2425
And I click on the number of people I am following on my profile
2526
Then I should see someone I'm following
26-
27+
28+
Scenario: I should always follow steve and vice versa
29+
When I click on the number of people I am following on my profile
30+
Then I should see 'Steve'

spec/models/user_spec.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require 'spec_helper'
22

33
describe User do
4-
5-
let(:bob){Fabricate(:user)}
4+
let(:bob){Fabricate(:user, :username => 'hacker')}
65
let(:mozart){Fabricate(:user)}
7-
6+
let(:hello_world){Fabricate(:program, :author_username => bob.username)}
7+
88
it 'can be created validly' do
99
bob.should be_valid
1010
mozart.should be_valid
@@ -17,4 +17,14 @@
1717
bob.reload
1818
bob.following?(mozart).should be_false
1919
end
20+
21+
describe 'programs' do
22+
it 'should return programs list' do
23+
bob.programs.class.should == Plucky::Query
24+
hello_world.author_username.should == 'hacker'
25+
bob.username.should == 'hacker'
26+
bob.programs.count.should == 1
27+
bob.programs.first.should == hello_world
28+
end
29+
end
2030
end

0 commit comments

Comments
 (0)