Last active
August 29, 2015 14:00
-
-
Save drager/06dc4b30c1528d6a392c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FactoryGirl.define do | |
factory :category do | |
name 'Programming' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Failures: | |
1) Create topic creates a topic successfully with a valid name and bodytext | |
Failure/Error: current_path.should == forum_topic_path(forum, topic) | |
ActionController::UrlGenerationError: | |
No route matches {:action=>"show", :controller=>"topics", :format=>nil, :forum_id=>#<Forum id: 1020, category_id: 1013, name: "ruby", description: "Laudantium tot | |
it. Ea ipsa voluptatibus no...", order: 0, created_at: "2014-04-30 14:32:39", updated_at: "2014-04-30 14:32:39", slug: "ruby">, :id=>nil} missing required keys: [:id] | |
# ./spec/features/create_topics_spec.rb:22:in `block (2 levels) in <top (required)>' | |
Finished in 0.86605 seconds | |
3 examples, 1 failure | |
Failed examples: | |
rspec ./spec/features/create_topics_spec.rb:18 # Create topic creates a topic successfully with a valid name and bodytext | |
Randomized with seed 37786 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
require 'faker' | |
feature 'Create topic' do | |
let(:category) { create(:category) } | |
let(:forum) { create(:forum) } | |
let(:user) { create(:user) } | |
background do | |
@email = '[email protected]' | |
@password = 'test123' | |
@user = create(:user, username: 'ellen.u', email: @email, password: @password, password_confirmation: @password) | |
end | |
scenario 'creates a topic successfully with a valid name and bodytext' do | |
sign_in_with(@email, @password) | |
create_topic('Hello World!', Faker::Lorem.paragraph) | |
current_path.should == forum_topic_path(forum, Topic.find_by(name: 'Hello World!')) | |
user_sees_success_message('Topic was successfully created1.') | |
end | |
scenario 'notifies the user if the name is to short' do | |
sign_in_with(@email, @password) | |
create_topic(nil, '12345678912345678912') | |
user_sees_error_message('Name is too short (minimum is 6 characters)') | |
end | |
scenario 'notifies the user if the bodytext is to short' do | |
sign_in_with(@email, @password) | |
create_topic('test-name', '1234567891234567891') | |
user_sees_error_message('Posts bodytext is too short (minimum is 20 characters)') | |
end | |
def user_sees_error_message(message) | |
expect(page).to have_css '.alert', message | |
end | |
def user_sees_success_message(message) | |
expect(page).to have_css '.notice', message | |
end | |
def sign_in_with(email, password) | |
visit session_path | |
fill_in 'Email', with: email | |
fill_in 'Password', with: password | |
click_button 'Login' | |
end | |
def create_topic(name, bodytext) | |
visit new_forum_topic_path(forum) | |
fill_in 'Name', with: name | |
fill_in 'Bodytext', with: bodytext | |
click_button 'Create Topic' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FactoryGirl.define do | |
factory :forum do | |
name 'ruby' | |
association :category | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'faker' | |
FactoryGirl.define do | |
factory :post do | |
association :topic | |
bodytext Faker::Lorem.paragraph | |
association :user | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FactoryGirl.define do | |
factory :topic do | |
association :forum | |
name 'Programming' | |
association :user | |
association :post | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'faker' | |
FactoryGirl.define do | |
factory :user do | |
email {Faker::Internet.email} | |
username {Faker::Internet.user_name} | |
first_name {Faker::Name.first_name} | |
last_name {Faker::Name.last_name} | |
password 'test123' | |
password_confirmation 'test123' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment