Skip to content

Instantly share code, notes, and snippets.

View yukas's full-sized avatar

Yury Kaspiarovich yukas

View GitHub Profile
def method
end
def render_order(bar)
render partial: “order”, locals: { foo: bar }
end
# Set current application time zone to user's one
def set_time_zone
Time.zone = current_user.time_zone if user_signed_in?
end
# Somewhere in code
Time.zone.now # obtain current time in current user's time zone
require "csv"
class Client
def import
importer = CsvProductImporter.new(params[:file_path])
inventory = Inventory.new(importer)
inventory.import_products
end
end
=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')
class Vertice
attr_accessor :predecessor, :d, :name
def initialize(n)
@name = n
end
end
class Edge
attr_accessor :source, :destination, :w
def initialize(s,d,w)
@yukas
yukas / authentication_spec.rb
Created May 18, 2016 09:33
Bare feature spec
require "spec_helper"
feature "Authentication" do
before do
Traver.create(user: { email: "walter@white.com", password: "walter" })
end
scenario "User logs in successfully by entering email and password" do
visit login_path
RSpec::Matchers.define :login_successfully do
match do |login_page|
expect(login_page.page).to have_content "Successfully logged in."
end
end
class OrderCalulator
attr_reader :order
attr_reader :total, :fee
def initialize(order)
@order = order
end
def calculate
@total = calculate_total
require "spec_helper"
describe OrderReport do
subject {
Traver.create(order_report: {
order: { items: [{ price: 1.0 }, { price: 2.0 }] }
})
}
describe "#update_order_report" do