Skip to content

Instantly share code, notes, and snippets.

View mpugach's full-sized avatar

Maksym Pugach mpugach

View GitHub Profile
@mpugach
mpugach / form_for.drop_down_list.date_select.html.erb
Created July 25, 2012 07:15
Form_for drop down list and date select fields.
<%= form_for(@person) do |f| %>
<%= f.label :gender %>
<%= f.select :gender, options_for_select([["Male", true], ["Female", false]]) %>
<%-# in this case :gender is boolean -%>
<%= f.label :birthdate, "Birthday" %>
<%= f.date_select :birthdate, :start_year => 1940 %>
<%= f.submit "Submit" %>
//
// Sass CSS reset
//
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
#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}), через які неможливо зберегти зміни:"