Skip to content

Instantly share code, notes, and snippets.

View akirill0v's full-sized avatar

Alexander Kirillov akirill0v

View GitHub Profile
# gem install capybara --pre
# gem install rspec
# rspec capybara_test.rb
require 'rubygems'
require 'capybara'
require 'capybara/rspec'
Capybara.configure do |c|
c.current_driver = :selenium
@akirill0v
akirill0v / config.rb
Created October 29, 2012 09:52
Serve static html files with thin
root=Dir.pwd
puts ">>> Serving: #{root}"
run Rack::Directory.new("#{root}")
@akirill0v
akirill0v / example.rb
Created October 31, 2012 09:45 — forked from joakimk/example.rb
A simple form object built on top of virtus.
class Filter
include FormObject
# Proc because Date.yesterday changes every day :)
attribute :from, Date, default: Proc.new { Date.yesterday }
attribute :to, Date, default: Proc.new { 1.month.from_now - 1.day }
end
# in controller
@filter = Filter.new(params[:filter])
signals 'hit()', 'missed()', 'angleChanged(int)', 'forceChanged(int)',
'canShoot(bool)'
slots 'setAngle(int)', 'setForce(int)', 'shoot()', 'moveShot()',
'newTarget()', 'setGameOver()', 'restartGame()'
#...
def restartGame()
if isShooting()
@akirill0v
akirill0v / example.rb
Created November 13, 2012 19:21 — forked from joakimk/example.rb
A simple form object built on top of virtus.
class Filter
include FormObject
# Proc because Date.yesterday changes every day :)
attribute :from, Date, default: Proc.new { Date.yesterday }
attribute :to, Date, default: Proc.new { 1.month.from_now - 1.day }
end
# in controller
@filter = Filter.new(params[:filter])
@akirill0v
akirill0v / access_helper.rb
Created November 22, 2012 10:42
Модуль? который инклудится в нужный нам класс, например ApplicationController.rb
module AccessHelper
# ...
def acl
YaAcl::Acl.instance
end
def can?(route_method, action = nil, options = {})
url_options = send "hash_for_#{route_method}_path"
resource = "#{url_options[:controller].to_s.camelize}Controller"
class Role < ActiveRecord::Base
include RoleRepository
has_many :user_roles, :dependent => :destroy
has_many :users, :through => :user_roles
translate_methods :name
def to_sym
short_name.to_sym
end
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"
# Example aliases
@akirill0v
akirill0v / pavel.rb
Last active December 12, 2015 05:18
Павлик Морозов
class Parent
def test
puts "test"
end
private :test
end
class Child < Parent
public :test
@akirill0v
akirill0v / support.rb
Created February 12, 2013 10:54
sqlite in memory
require 'active_record'
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
ActiveRecord::Migration.create_table :users do |t|
t.string :email
t.string :name
t.timestamps
end