This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "spec_helper" | |
describe OrderCalculator do | |
let(:order) { | |
Traver.create(order: { | |
items: [{ price: 1.0 }, { price: 2.0 }] | |
}) | |
} | |
subject { OrderCalculator.new(order) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderReport < ActiveRecord::Base | |
belongs_to :order | |
def update_order_report | |
this.total = calculator.total | |
this.fee = calculator.fee | |
save! | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderCalulator | |
attr_reader :order | |
attr_reader :total, :fee | |
def initialize(order) | |
@order = order | |
end | |
def calculate | |
@total = calculate_total |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec::Matchers.define :login_successfully do | |
match do |login_page| | |
expect(login_page.page).to have_content "Successfully logged in." | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LoginPage | |
include Capybara::DSL | |
include Rails.application.routes.url_helpers | |
def visit | |
super login_path | |
end | |
def login_with(params = {}) | |
fill_login_form(params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "spec_helper" | |
feature "Authentication" do | |
before do | |
Traver.create(user: { email: "walter@white.com", password: "walter" }) | |
end | |
let(:login_page) { LoginPage.new } | |
scenario "User logs in successfully by entering email and password" do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "csv" | |
class Client | |
def import | |
importer = CsvProductImporter.new(params[:file_path]) | |
inventory = Inventory.new(importer) | |
inventory.import_products | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def render_order(bar) | |
render partial: “order”, locals: { foo: bar } | |
end |