Skip to content

Instantly share code, notes, and snippets.

View jwood's full-sized avatar

John Wood jwood

View GitHub Profile
Installing cocaine 0.5.7
Installing crack 0.4.2
Installing chronic 0.10.2
Installing hitimes 1.2.2 with native extensions
Installing bourbon 4.2.3
@jwood
jwood / questions.rake
Created July 13, 2015 14:03
Example of rake task that migrates production data
namespace :question do
desc "Update Questions and Tasks to support newly added validations"
task :update_for_validations => :environment do
ActiveRecord::Base.transaction do
# Set question_type to "yesno" for following questions:
%w(need_long_term_rental need_short_term_rental find_eye_doctor cleaning need_home).each do |identifier|
q = Question.find_by_identifier(identifier)
q.update_attributes!(question_type: "yesno") if q.present?
end
@jwood
jwood / account.rb
Created July 10, 2015 13:57
Rails uniqueness validation
class Account < ActiveRecord::Base
validates :email, uniqueness: true
end
require "rails_helper"
class CompanyOfficePage < SitePrism::Page
set_url "/company"
element :select_office, ".select-office"
element :office_name, "#office-name"
element :save_office_button, "#save-office-btn"
element :company_tasks, ".company-tasks"
element :company_faqs, ".company-faqs"
require "rails_helper"
feature "Company/Office page spec", js: true do
let(:company) { FactoryGirl.create(:company) }
let(:employee) { FactoryGirl.create(:employee, full_city: "Chicago, IL", company: company) }
let!(:office_1) { FactoryGirl.create(:office, company: company, address: FactoryGirl.attributes_for(:chicago_address)) }
let!(:office_2) { FactoryGirl.create(:office, company: company, address: FactoryGirl.attributes_for(:chicago_address)) }
let!(:office_task) { FactoryGirl.create(:task, company: company, office: office_1) }
let!(:office_faq) { FactoryGirl.create(:faq, company: company, office: office_1) }
SitePrism.configure do |config|
config.use_implicit_waits = true
end
my_page_object.wait_until_blah_visible
expect(page).to have_selector("#blah", visible: true)
expect(my_page_object).to have_blah
@jwood
jwood / css_existence.rb
Last active August 29, 2015 14:22
Testing for existence using CSS
expect(page).to have_css("#blah")