Instantly share code, notes, and snippets.

@palkan /shared_account.rb Secret
Last active Jun 10, 2018

Embed
What would you like to do?
[AnyFixture] shared account
require "test_prof/any_fixture/dsl"
require "test_prof/ext/active_record_refind"
using TestProf::AnyFixture::DSL
using TestProf::Ext::ActiveRecordRefind
shared_context "feature account", type: :feature do
prepend_before(:all) do
account = fixture(:account) do
build(:account,
name: 'Star Wars',
slug: "sw").tap do |acc|
acc.owner = build :user,
email: 'dw@sw.spec', name: 'Darth Vader',
password: 'theforce',
password_confirmation: 'theforce',
owner: true
acc.default_brand = build(:brand, name: 'Paranoid Droid', slug: 'paranoid-droid')
acc.save!
end
end
brand = fixture(:brand) { @account.default_brand }
fixture(:vader) { @account.owner }
location_group = fixture(:location_group) do
create :location_group, name: "Arkanis", account: account
end
location = fixture(:location) do
create :location, name: "Tatooine",
account: account, group: location_group,
brand: brand,
country_code: 'VU' # Vanuatu; they eat humans!
end
position = fixture(:position) do
create :position, account: account, name: "Stormtrooper"
end
funnel = fixture(:funnel) do
create(:funnel, :with_stages, :with_active_campaign,
account: account,
location: location,
position: position,
title: "#{location.name} - #{position.name}").tap do |f|
create(:stage, funnel: f, title: 'Welcome to Death Star')
end
end
landing_stage = funnel.stages(true).find { |s| s.title == 'Welcome to Death Star' }
luke = fixture(:luke) do
create(
:applicant, stage: landing_stage,
name: 'Luke Skywalker', email: 'luke@sw.spec',
key: 'luke-1'
)
end
fixture(:luke_identity) do
create(
:portal_applicant, full_name: 'Luke Skywalker',
first_name: 'Luke', last_name: 'Skywalker',
email: 'luke@sw.spec',
password: 'theforce',
password_confirmation: 'theforce'
).tap do |ident|
ident.applicants << luke
end
end
fixture(:finn) do
create(
:applicant, stage: landing_stage,
name: 'Finn', email: 'fn2187@sw.spec',
key: 'fn-2187'
)
end
end
# Ensure that every example has a fresh copy of a record
%i[
account brand funnel stage position location location_group
vader luke luke_identity finn
].each do |id|
let(id) { fixture(id).refind }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment