Skip to content

Commit

Permalink
Added account creation and program page tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dominic committed Jan 8, 2012
1 parent f18d01c commit 94c20a0
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 5 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ end
group :test do
gem "mocha"
gem "database_cleaner"
gem "launchy"
end
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ GEM
activesupport (= 3.1.0)
activesupport (3.1.0)
multi_json (~> 1.0)
addressable (2.2.6)
arel (2.2.1)
bcrypt-ruby (3.0.1)
bson (1.5.2)
Expand Down Expand Up @@ -112,6 +113,8 @@ GEM
thor (~> 0.14)
json (1.6.4)
kgio (2.7.2)
launchy (2.0.5)
addressable (~> 2.2.6)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
Expand Down Expand Up @@ -244,6 +247,7 @@ DEPENDENCIES
jnunemaker-validatable (>= 1.8.4)
jquery-rails
json
launchy
mm-devise (>= 1.2)
mocha
mongo_mapper
Expand Down
Empty file removed app/views/users/_form.html.haml
Empty file.
2 changes: 1 addition & 1 deletion app/views/users/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
%h4= resource.about
%hr
%p
= link_to pluralize(resource.programs.count, "Program"), user_programs_path(resource)
= link_to pluralize(resource.programs.count, "Program"), user_programs_path(resource), :class => "user-programs"
%p
Following:
=link_to resource.following.count, resource_path(resource) + "/following"
Expand Down
16 changes: 16 additions & 0 deletions features/programs.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Feature: Access Programs

As a user of the site, I want to access users' programs

Scenario: View a featured program
Given there is a featured program
Then I should be able to view a highlighted program

Scenario: View my programs
Given a logged in user
And I have uploaded a program
Then I should be able to view my programs

Scenario: View another user's programs
Given a user has uploaded a program
Then I should be able to view their programs
7 changes: 7 additions & 0 deletions features/signup.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: Sign up for an account

As a new Hackety user, I want to create a new account and log in with it

Scenario: Create an account via the signup form
When I register a new account
Then I should be logged in with my new account
47 changes: 47 additions & 0 deletions features/step_definitions/program_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Given /^there is a featured program$/ do
@program = Program.create!(:author_username => "username",
:slug => "slug",
:title => "My Featured Program",
:featured => true)
end

Then /^I should be able to view a highlighted program$/ do
visit programs_path
within "#featured" do
page.should have_content("My Featured Program")
end
end

def upload_program(user)
@program = Program.create!(:author_username => user.username,
:slug => "slug",
:title => "#{user.username}'s program")
end

Given /^I have uploaded a program$/ do
upload_program(@user)
end

Given /^a user has uploaded a program$/ do
@user = User.create!(:username => "some_user",
:password => "password",
:password_confirmation => "password",
:email => "some_user@example.com")
upload_program(@user)
end

def visit_user_programs_page
visit user_path(@user)
within ".about-user" do
find(".user-programs").click()
end
page.should have_content(@program.title.titleize)
end

Then /^I should be able to view my programs$/ do
visit_user_programs_page
end

Then /^I should be able to view their programs$/ do
visit_user_programs_page
end
17 changes: 17 additions & 0 deletions features/step_definitions/signup_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
When /^I register a new account$/ do
@user_info = {:username => "username", :password => "password", :email => "test@example.com"}

visit new_user_registration_path

fill_in("Username", :with => @user_info[:username])
fill_in("Email", :with => @user_info[:email])
fill_in("Password", :with => @user_info[:password])
fill_in("Password confirmation", :with => @user_info[:password])

click_button "Sign up"
end

When /^I should be logged in with my new account$/ do
page.should have_content("You have signed up successfully")
page.should have_content(@user_info[:username])
end
2 changes: 1 addition & 1 deletion features/step_definitions/user_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def login_user
email: "test_user@example.com",
password: "foobar",
password_confirmation: "foobar")
visit('/login')
visit login_path
fill_in("Username", :with => @user.username)
fill_in("Password", :with => @user.password)
click_button("Sign in")
Expand Down
6 changes: 3 additions & 3 deletions features/users.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Feature: Manage account

As a user of this site, I can view and update my profile

Background: The user is logged in
Expand All @@ -8,8 +8,8 @@ Feature: Manage account
Scenario: View my profile
When I go to look at my profile page
Then it should have the right information

Scenario: Edit my profile
When I edit my profile
Then I should be notified that my profile was updated
And I should see my changes reflected on my profile page
And I should see my changes reflected on my profile page

0 comments on commit 94c20a0

Please sign in to comment.