Skip to content

Instantly share code, notes, and snippets.

View ildarsafin's full-sized avatar

Ildar Safin ildarsafin

View GitHub Profile
@ildarsafin
ildarsafin / capybara cheat sheet
Last active August 29, 2015 14:27 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=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')
@ildarsafin
ildarsafin / rspec_rails_cheetsheet.rb
Last active August 29, 2015 14:27 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@ildarsafin
ildarsafin / scopes_in_tasks_model.rb
Last active August 29, 2015 14:02
All scopes in task model
scope :complete, ->(value) { where(summary_status: 'complete', state: 'active').limit(value) }
scope :accessible_by_user, ->(user) do
includes(:assignee_tasks)
.where('tasks.user_id = :user_id or assignee_tasks.user_id = :user_id', user_id: user.id)
end
scope :accessible_by_user_with_state, ->(user, state) do
includes(:assignee_tasks)
.where('tasks.user_id = :user_id AND tasks.state = :state OR assignee_tasks.user_id = :user_id AND assignee_tasks.state = :state',
user_id: user.id, state: state)
end