Skip to content

Instantly share code, notes, and snippets.

View drager's full-sized avatar
🦀
🦀 🕸️

Jesper Håkansson drager

🦀
🦀 🕸️
View GitHub Profile
= form_for([@forum, @topic]) do |f|
- if @topic.errors.any?
%div{id: 'error_explanation'}
%h2
= pluralize(@topic.errors.count, "error")
prohibited this topic from being saved:
- for message in @topic.errors.full_messages
%li
= message
require 'spec_helper'
describe "CreateTopics" do
it "creates topics" do
@forum = Forum.create(name: 'Ruby')
visit new_forum_topic_path, @forum.slug
fill_in "Name", with: "Test"
click_button "Submit"
end
require 'spec_helper'
require 'faker'
feature 'Create user' do
scenario 'creates a user successfully with a valid username, email and password' do
register_with Faker::Internet.user_name, 'test123', 'test123', Faker::Internet.email
user_sees_success_message "Registered successfully!"
end
scenario 'notifies the user if his username is invalid' do
FactoryGirl.define do
factory :category do
name 'Programming'
end
end
Topic
is valid if all parameters match (FAILED - 1)
Failures:
1) Topic is valid if all parameters match
Failure/Error: build(:topic).should be_valid
ActiveRecord::RecordInvalid:
Validation failed: Username has already been taken
# C:in `object'
= form_for([@forum, @topic]) do |f|
- if @topic.errors.any?
%div{class: 'alert'}
%h2
= pluralize(@topic.errors.count, 'error')
prohibited this topic from being saved:
- for message in @topic.errors.full_messages
%li
= message
= form_for(:user) do |f|
- if flash[:alert]
%div{class: 'alert'}
= flash[:alert]
= f.label :email
%div{class: 'field'}
= f.email_field :email
Parameters:
{"_method"=>"put",
"authenticity_token"=>"eDv4pcLTU0m3os+7OImIOdNQxouyQoSb3FojGMXMNh8=",
"forum_id"=>"ruby",
"topic_id"=>"asdasdasdasdasd"}
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
private
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
rescue ActiveRecord::RecordNotFound
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')