Skip to content

Instantly share code, notes, and snippets.

View mpugach's full-sized avatar

Maksym Pugach mpugach

View GitHub Profile
#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')
// layout file
<body>
<div class="container">
<%= flash_messages %>
<%= yield %>
</div><!-- /container -->
</body>
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>
class ApplicationController < ActionController::Base
# Includes Authorization mechanism
include Pundit
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
# Globally rescue Authorization Errors in controller.
require 'spec_helper'
describe PersonPolicy do
subject { PersonPolicy }
let(:person) { create(:person) }
let(:user) { create(:valid_user) }
context 'given user\'s role activities' do
class CreateRoles < ActiveRecord::Migration
def change
create_table :roles do |t|
t.string :activities, array: true, length: 30, using: 'gin', default: '{}'
t.timestamps
end
end
end
##
def screenshot
require 'capybara/util/save_and_open_page'
now = Time.now
p = "/#{now.strftime('%Y-%m-%d-%H-%M-%S')}-#{rand}"
Capybara.save_page body, "#{p}.html"
path = Rails.root.join("#{Capybara.save_and_open_page_path}" "#{p}.png").to_s
page.driver.render path
Launchy.open path
end
uk:
errors:
messages:
expired: "прострочено, створіть новий"
not_found: "не знайдено"
already_confirmed: "вже було підтверджено, спробуйте увійти"
not_locked: "не було заблоковано"
not_saved:
one: "Виникла помилка, через яку неможливо зберегти зміни:"
other: "Виникли помилки (загалом - %{count}), через які неможливо зберегти зміни:"

Capybara

save_and_open_page

Matchers

have_button(locator)
@mpugach
mpugach / puma.rb
Last active August 29, 2015 14:12 — forked from catsby/puma.rb
preload_app!
min_threads = Integer(ENV['MIN_THREADS'] || 0)
max_threads = Integer(ENV['MAX_THREADS'] || 5)
threads min_threads, max_threads
workers Integer(ENV['WORKER_COUNT'] || 3 )
on_worker_boot do
ActiveSupport.on_load(:active_record) do