2017 refactor

This commit is contained in:
Godwin
2017-04-09 11:37:16 -07:00
parent 3d00b70087
commit d1db46ffaf
302 changed files with 7100 additions and 8082 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

+56 -129
View File
@@ -1,157 +1,84 @@
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
# It is recommended to regenerate this file in the future when you upgrade to a
# newer version of cucumber-rails. Consider adding your own code to a new file
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.
require 'cucumber/rails'
require 'capybara/poltergeist'
require 'lingua_franca/capybara'
require 'mocha/mini_test'
require 'fileutils'
require 'marmara'
# Capybara defaults to CSS3 selectors rather than XPath.
# If you'd prefer to use XPath, just uncomment this line and adjust any
# selectors in your step definitions to use the XPath syntax.
# Capybara.default_selector = :xpath
# By default, any exception happening in your Rails application will bubble up
# to Cucumber so that your scenario will fail. This is a different from how
# your application behaves in the production environment, where an error page will
# be rendered instead.
#
# Sometimes we want to override this default behaviour and allow Rails to rescue
# exceptions and display an error page (just like when the app is running in production).
# Typical scenarios where you want to do this is when you test your error pages.
# There are two ways to allow Rails to rescue exceptions:
#
# 1) Tag your scenario (or feature) with @allow-rescue
#
# 2) Set the value below to true. Beware that doing this globally is not
# recommended as it will mask a lot of errors for you!
#
ActionController::Base.allow_rescue = false
# Remove/comment out the lines below if your app doesn't have a database.
# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
begin
DatabaseCleaner.strategy = :truncation
#DatabaseCleaner.clean_with(:truncation)
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
DatabaseCleaner.strategy = :truncation, { except: %w[cities city_cache] }
Capybara.register_driver :bb_poltergeist do |app|
if ENV['CSS_TEST']
Marmara.options = {
ignore: [/paypal\./],
rewrite: {
from: /^.*\/(.*?)\/.*?\.css$/,
to: '\1.css'
},
minimum: {
declarations: 30
}
}
Marmara.start_recording
end
opts = {
timeout: 10,
window_size: [1200, 800]
}
Capybara::Poltergeist::Driver.new(app, opts)
end
Before('@javascript') do
ActiveRecord::Base.shared_connection = nil
ActiveRecord::Base.descendants.each do |model|
model.shared_connection = nil
end
ActiveRecord::Base.shared_connection = nil
ActiveRecord::Base.descendants.each do |model|
model.shared_connection = nil
end
end
Before do
# user_agent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36"
user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A"
#request.stub!(:user_agent).and_return()
#controller.request.stub!(:user_agent).and_return(user_agent)
ActionDispatch::Request.any_instance.stubs(:user_agent).returns(user_agent)
#page.driver.browser.header('User-Agent', user_agent)
#page.driver.headers = { "User-Agent" => "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2403.157 Safari/537.36" }
TestState.reset!
safari5 = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1"
chrome55 = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"
ActionDispatch::Request.any_instance.stubs(:user_agent).returns(safari5)
LinguaFranca.test_driver = page.driver
host = "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}"
LinguaFranca.host = host
Mail::TestMailer.deliveries.clear
end
After do |scenario|
#save_and_open_page if scenario.failed?
puts " = PAGE START = \n#{page.html}\n = PAGE END = " if scenario.failed?
#puts page.find('#main')['innerHTML'] if scenario.failed?
sleep 1
log_result scenario
LinguaFranca.screenshot_mail
if scenario.failed?
if @exception
puts @exception.to_s
puts @exception.backtrace.join("\n")
end
end
end
After do
DatabaseCleaner.clean
DatabaseCleaner.clean
end
#After('suite') do
# puts " ============ #{After all} ============ "
#end
AfterStep do
# capture used selectors to generate css coverage
Marmara.record(page) if Marmara.recording?
# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
# See the DatabaseCleaner documentation for details. Example:
#
# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
# # { :except => [:widgets] } may not do what you expect here
# # as Cucumber::Rails::Database.javascript_strategy overrides
# # this setting.
# DatabaseCleaner.strategy = :truncation
# end
#
# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
# DatabaseCleaner.strategy = :transaction
# end
#
# Possible values are :truncation and :transaction
# The :transaction strategy is faster, but might give you threading problems.
# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
Capybara.register_driver :bb_poltergeist do |app|
I18n.backend.start_recording_html(Capybara::LinguaFrancaPoltergeist::Driver.new(app, :inspector => true, :timeout => 120))
# take some extra time between steps if we're recording
sleep(0.5) if LinguaFranca.recording?
end
Cucumber::Rails::Database.javascript_strategy = :transaction
Capybara.default_driver = :bb_poltergeist
Capybara.javascript_driver = :bb_poltergeist
Geocoder.configure(:timeout => 60)
Geocoder.configure(timeout: 60)
def locate(id)
id = id.gsub(/\s+/, '_')
e = page.all("[name=\"#{id}\"], [id=\"#{id}\"]")
if e.length
return e.first[:id]
end
page.all("[name$=\"#{id}\"], [id$=\"#{id}\"]").first[:id]
end
def create_org(name = nil, location = nil)
org = FactoryGirl.create(:org)
found_location = nil
if location.present?
cache_file = File.join(File.dirname(__FILE__), 'location_cache.yml')
cache = {}
if File.exists?(cache_file)
begin
cache = YAML.load_file(cache_file)
rescue
# get rid of the cache if there's an error
end
end
l = cache[location]
if l.nil?
l = Geocoder.search(location).first
cache[location] = l
File.open(cache_file, 'w') { |f| f.write cache.to_yaml }
end
begin
found_location = Location.new(city: l.city, territory: l.province_code, country: l.country_code, latitude: l.latitude, longitude: l.longitude)
rescue; end
if found_location.nil?
# let it though, we might be offline
org.save!
return org
end
end
if name.present?
org.name = name
org.slug = org.generate_slug(name, found_location)
end
if found_location.present?
org.locations << found_location
end
org.save!
org
end
def get_language_code(language)
languages = {
'english' => 'en',
'french' => 'fr',
'spanish' => 'es',
'german' => 'de'
}
languages[language.downcase]
at_exit do
Marmara.stop_recording if Marmara.recording?
# LinguaFranca.capture_translations if LinguaFranca.recording?
end
+142 -20
View File
@@ -1,24 +1,146 @@
FactoryGirl.define do
factory :upcoming_conference, :class => 'Conference' do
title 'My Bike!Bike!'
slug 'MyBikeBike'
info 'Curabitur non nulla sit amet nisl tempus convallis quis ac lectus.'
poster 'poster.jpg'
cover 'cover.jpg'
registration_open false
start_date Date.today - 30.days
end_date Date.today - 26.days
conference_type_id (ConferenceType.find_by(:slug => 'bikebike') || ConferenceType.create(:slug => 'bikebike')).id
paypal_username 'joe'
locale 'en'
end
factory :upcoming_conference, class: :Conference do
info Forgery::LoremIpsum.paragraphs(2, sentences: 6, html: true, random: true)
start_date Date.new(2025, 9, 1)
end_date Date.new(2025, 9, 4)
conferencetype :annual
year 2025
paypal_username 'joe'
locale 'en'
is_public true
is_featured true
factory :org, :class => 'Organization' do
name 'My Organization'
info 'Curabitur non nulla sit amet nisl tempus convallis quis ac lectus.'
avatar 'avatar.jpg'
cover 'cover.jpg'
end
factory :upcoming_regional_conference, class: :Conference do
start_date Date.new(2025, 2, 14)
end_date Date.new(2025, 2, 16)
conferencetype :nw
end
factory :past_conference, class: :Conference do
start_date Date.new(2013, 10, 3)
end_date Date.new(2013, 10, 6)
year 2013
is_featured false
end
end
factory :registration, class: :ConferenceRegistration do
conference_id nil
user_id nil
is_attending 'y'
registration_fees_paid [25, 50, 100, Random.rand(10...150)].sample
arrival nil
departure nil
other Forgery::LoremIpsum.paragraph(random: true)
allergies Forgery::LoremIpsum.paragraph(random: true)
steps_completed [:policy, :contact_info, :questions, :hosting, :payment]
can_provide_housing false
housing_data {}
city_id 2
end
factory :org, class: :Organization do
name 'My Organization'
info 'Curabitur non nulla sit amet nisl tempus convallis quis ac lectus.'
end
factory :user, class: :User do
email Forgery::Internet.email_address
firstname Forgery::Name.full_name
end
factory :workshop, class: :Workshop do
conference_id nil
languages ['en'].to_json
end
end
World(FactoryGirl::Syntax::Methods)
World(FactoryGirl::Syntax::Methods)
def create_user(options = {})
options[:firstname] ||= Forgery(:name).full_name
options[:email] ||= Forgery(:internet).email_address
options[:languages] ||= ['en'].to_json
options[:languages] = options[:languages].to_json if options[:languages].is_a?(Array)
User.create(options)
end
def create_workshop(title, user = TestState.my_account)
workshop = FactoryGirl.build(:workshop)
workshop.conference_id = TestState.last_conference.id
workshop.title = title || Forgery::LoremIpsum.sentence(random: true).gsub(/\.$/, '').titlecase
workshop.theme = TestState::Sample[:workshop].all_themes
workshop.space = TestState::Sample[:workshop].all_spaces
workshop.needs = [TestState::Sample[:workshop].all_needs].to_json
workshop.info = Forgery::LoremIpsum.paragraphs(Random.rand(1..4), sentences: Random.rand(3..8), random: true)
workshop.save!
WorkshopFacilitator.create(user_id: user.id, workshop_id: workshop.id, role: :creator)
TestState.last_workshop = workshop
return workshop
end
def create_location(options)
location = EventLocation.new(options)
location.conference_id = TestState.last_conference.id
location.save!
return location
end
def create_registration(user = TestState.my_account)
registration = FactoryGirl.build(:registration)
registration.conference_id = TestState.last_conference.id
registration.user_id = user.id
registration.arrival = TestState.last_conference.start_date
registration.departure = TestState.last_conference.end_date
registration.housing = TestState::Sample[:conference_registration].all_housing_options
registration.bike = TestState::Sample[:conference_registration].all_bike_options
registration.food = TestState::Sample[:conference_registration].all_food_options
registration.save!
if user == TestState.my_account
TestState.my_registration = registration
else
TestState.last_registration = registration
end
return registration
end
def create_org(name = nil, location = nil)
org = FactoryGirl.create(:org)
found_location = nil
if location.present?
cache_file = File.join(File.dirname(__FILE__), 'location_cache.yml')
cache = {}
if File.exists?(cache_file)
begin
cache = YAML.load_file(cache_file)
rescue
# get rid of the cache if there's an error
end
end
l = cache[location]
if l.nil?
l = Geocoder.search(location).first
cache[location] = l
File.open(cache_file, 'w') { |f| f.write cache.to_yaml }
end
begin
found_location = Location.new(city: l.city, territory: l.province_code, country: l.country_code, latitude: l.latitude, longitude: l.longitude)
rescue; end
if found_location.nil?
# let it though, we might be offline
org.save!
return org
end
end
if name.present?
org.name = name
org.slug = org.generate_slug(name, found_location)
end
if found_location.present?
org.locations << found_location
end
org.save!
org
end
+194
View File
@@ -0,0 +1,194 @@
include Sorcery::TestHelpers::Rails
def locate(id)
id = id.gsub(/\s+/, '_')
e = page.all("[name=\"#{id}\"], [id=\"#{id}\"], [id^=\"#{id}--\"]")
return e.first[:id]
end
def selector_for(id)
prefixes = ['body.has-overlay .dlg.open ', 'body #primary-content ']
selectors = ['[name="{id}"]', '[id="{id}"]', '[id^="{id}--"]']
selector = []
prefixes.each do | pre |
selectors.each do | sel |
selector << "#{pre}#{sel}".gsub(/\{id\}/, id)
end
end
selector.join(',')
end
def get_language_code(language)
languages = {
'english' => 'en',
'french' => 'fr',
'spanish' => 'es',
'german' => 'de'
}
languages[language.downcase]
end
def to_filename(filename)
filename.gsub(/[^\w\s_-]+/, '')
.gsub(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
.gsub(/\s+/, '_')
end
def log_result(scenario)
if Capybara.current_session.server.present?
dir = "log/test-results/#{to_filename(scenario.feature.name)}"
FileUtils::mkdir_p dir
filename = "#{to_filename(scenario.name)}.html"
File.write("#{dir}/#{filename}", capture_html)
end
end
def capture_html(distance_from_root = 3)
html = page.html
host = "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}"
public_dir = "#{'../' * distance_from_root}public/"
html.gsub(/(=\"|\(['"]?)(?:#{host})?\/(assets|uploads)/, "\\1#{public_dir}\\2")
end
def attempt_to(&block)
begin
retries ||= 0
timeout ||= 0
timeout += 1
yield
rescue Exception => e
raise e unless (retries += 1) <= 4
# puts "Failed: #{e}"
# puts "Retry ##{retries}"
sleep(timeout * timeout)
retry
end
end
def last_email_html
if TestState.last_email.parts
TestState.last_email.parts.last.body.raw_source
else
TestState.last_email.body.raw_source
end
end
def find_in_last_email(selector, attribute = nil)
html = last_email_html.gsub(/^.*?(<table .*<\/table>).*$/m, '\1').gsub(/\n/, ' ').gsub(/\'/, '\\\'')
Nokogiri::HTML(html).at(selector).attr(attribute)
end
def emails_to(email_address, subject = nil)
ActionMailer::Base.deliveries.select do |mail|
mail.to.include?(email_address) &&
(subject.nil? || mail.subject.downcase =~ /#{Regexp.escape(subject.downcase)}/)
end
end
def str_to_num(num)
nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
return nums.find_index(num) if nums.include?(num)
case num
when 'no', 'none'
return 0
when 'a', 'an'
return 1
when 'two', 'couple', 'a couple', 'couple of', 'a couple of'
return 2
end
return num.to_i if num =~ /\d+/
fail "Could not interpret '#{num}' as a number"
end
def compare(expected, actual, negate = false)
case expected
when /any|some/
expectation = (be >= 1)
else
expectation = (be == str_to_num(expected))
end
expect(actual).send(negate ? :not_to : :to, expectation)
end
def email_address(user)
case user
when /(I|me)/
TestState.last_email_entered || TestState.my_account.email
when /^(?:the )?site administrator$/i
'goodgodwin@hotmail.com'
when /^'(.+)'$/
get_user($1).email
else
user
end
end
def get_locale(language)
return ({
spanish: :es,
english: :en,
french: :fr,
german: :de,
klingon: :tlh
}[language.strip.downcase.to_sym] or fail "Unable to convert '#{language.trim}' into a locale")
end
def get_field(field)
field = field.gsub(/^\s*(my|the)\s*(.+)$/, '\2').gsub(/\s/, '_')
aliases = {'phone_number' => 'phone', 'email_address' => 'email'}
return aliases[field] || field
end
def get_user(username)
return create_user unless username.present?
TestState::Users[username] = create_user({
(username =~ /^[^\s]+@[^\s]+\.[^\s]+$/ ? :email : :firstname) => username
}) unless TestState::Users[username].present?
return TestState::Users[username]
end
def element_with_text(text, parent = page)
smallest = nil
parent.all('*', text: text).each do |node|
smallest = node if smallest.nil? || smallest.native['outerHTML'].length > node.native['outerHTML'].length
end
return smallest
end
def parent_element(node)
node.first(:xpath, './/..')
end
def headers_to_attributes(object)
new_object = {}
object.each do |key, value|
new_object[key.underscore] = value
end
return new_object
end
def string_to_time(str)
h, m = str.split(':')
h = h.to_i
m = m.to_i
h += 12 if h < 6
return h + (m > 0 ? 0.5 : 0)
end
def string_to_time_length(str)
parts = str.match(/^(?:(\d+) hour)?\s*(?:(\d+) minutes)?$/)
return (parts[1] || '0').to_i + ((parts[2] || '0').to_i > 0 ? 0.5 : 0)
end
def str_to_wday(str)
return [:sun, :mon, :tue, :wed, :thu, :fri, :sat].index(str[0...3].downcase.to_sym)
end
+443 -44
View File
@@ -1,24 +1,74 @@
---
" in Halifax NS": !ruby/object:Geocoder::Result::Google
Brooklyn NY: !ruby/object:Geocoder::Result::Google
data:
address_components:
- long_name: Halifax
short_name: Halifax
- long_name: Brooklyn
short_name: Brooklyn
types:
- locality
- political
- long_name: Halifax
short_name: Halifax
types:
- administrative_area_level_3
- political
- long_name: Halifax Regional Municipality
short_name: Halifax Regional Municipality
- sublocality
- sublocality_level_1
- long_name: Kings County
short_name: Kings County
types:
- administrative_area_level_2
- political
- long_name: Nova Scotia
short_name: NS
- long_name: New York
short_name: NY
types:
- administrative_area_level_1
- political
- long_name: United States
short_name: US
types:
- country
- political
formatted_address: Brooklyn, NY, USA
geometry:
bounds:
northeast:
lat: 40.739446
lng: -73.8333651
southwest:
lat: 40.551042
lng: -74.05663
location:
lat: 40.6781784
lng: -73.9441579
location_type: APPROXIMATE
viewport:
northeast:
lat: 40.739446
lng: -73.8333651
southwest:
lat: 40.551042
lng: -74.05663
place_id: ChIJCSF8lBZEwokRhngABHRcdoI
types:
- political
- sublocality
- sublocality_level_1
cache_hit:
Yellowknife: !ruby/object:Geocoder::Result::Google
data:
address_components:
- long_name: Yellowknife
short_name: Yellowknife
types:
- locality
- political
- long_name: Fort Smith, Unorganized
short_name: Fort Smith, Unorganized
types:
- administrative_area_level_3
- political
- long_name: Fort Smith Region
short_name: Fort Smith Region
types:
- administrative_area_level_2
- political
- long_name: Northwest Territories
short_name: NT
types:
- administrative_area_level_1
- political
@@ -27,42 +77,291 @@
types:
- country
- political
formatted_address: Halifax, NS, Canada
- long_name: X0E
short_name: X0E
types:
- postal_code
- postal_code_prefix
formatted_address: Yellowknife, NT X0E, Canada
geometry:
bounds:
northeast:
lat: 44.7035313
lng: -63.5576784
lat: 62.5412576
lng: -114.299678
southwest:
lat: 44.5949302
lng: -63.68627009999999
lat: 62.4084661
lng: -114.518312
location:
lat: 44.6488625
lng: -63.5753196
lat: 62.4539717
lng: -114.3717886
location_type: APPROXIMATE
viewport:
northeast:
lat: 44.7035313
lng: -63.5576784
lat: 62.5412577
lng: -114.299678
southwest:
lat: 44.5949302
lng: -63.68627009999999
partial_match: true
place_id: ChIJwfrbBxQhWksR3C2LQ6bja2Y
lat: 62.4084945
lng: -114.518312
place_id: ChIJyYJGoyzx0VMRge9xQyQ3wbQ
types:
- locality
- political
cache_hit:
" in Sackville NB": !ruby/object:Geocoder::Result::Google
New Orleans: !ruby/object:Geocoder::Result::Google
data:
address_components:
- long_name: Sackville
short_name: Sackville
- long_name: New Orleans
short_name: New Orleans
types:
- locality
- political
- long_name: Westmorland County
short_name: Westmorland County
- long_name: Orleans Parish
short_name: Orleans Parish
types:
- administrative_area_level_2
- political
- long_name: Louisiana
short_name: LA
types:
- administrative_area_level_1
- political
- long_name: United States
short_name: US
types:
- country
- political
formatted_address: New Orleans, LA, USA
geometry:
bounds:
northeast:
lat: 30.199332
lng: -89.625053
southwest:
lat: 29.8666609
lng: -90.14007389999999
location:
lat: 29.95106579999999
lng: -90.0715323
location_type: APPROXIMATE
viewport:
northeast:
lat: 30.1748625
lng: -89.6269311
southwest:
lat: 29.86842459999999
lng: -90.1380099
place_id: ChIJZYIRslSkIIYRtNMiXuhbBts
types:
- locality
- political
cache_hit:
Drumheller AB: !ruby/object:Geocoder::Result::Google
data:
address_components:
- long_name: Drumheller
short_name: Drumheller
types:
- locality
- political
- long_name: Division No. 5
short_name: Division No. 5
types:
- administrative_area_level_2
- political
- long_name: Alberta
short_name: AB
types:
- administrative_area_level_1
- political
- long_name: Canada
short_name: CA
types:
- country
- political
formatted_address: Drumheller, AB, Canada
geometry:
bounds:
northeast:
lat: 51.488701
lng: -112.4530051
southwest:
lat: 51.3208389
lng: -112.806076
location:
lat: 51.4651847
lng: -112.7105343
location_type: APPROXIMATE
viewport:
northeast:
lat: 51.488701
lng: -112.4530051
southwest:
lat: 51.3208389
lng: -112.806076
place_id: ChIJHx_0B4ANc1MRWZCRwItZUUw
types:
- locality
- political
cache_hit:
Portland OR: !ruby/object:Geocoder::Result::Google
data:
address_components:
- long_name: Portland
short_name: Portland
types:
- locality
- political
- long_name: Multnomah County
short_name: Multnomah County
types:
- administrative_area_level_2
- political
- long_name: Oregon
short_name: OR
types:
- administrative_area_level_1
- political
- long_name: United States
short_name: US
types:
- country
- political
formatted_address: Portland, OR, USA
geometry:
bounds:
northeast:
lat: 45.654424
lng: -122.4718489
southwest:
lat: 45.432393
lng: -122.8369952
location:
lat: 45.5230622
lng: -122.6764816
location_type: APPROXIMATE
viewport:
northeast:
lat: 45.6524799
lng: -122.4718489
southwest:
lat: 45.432393
lng: -122.8369952
place_id: ChIJJ3SpfQsLlVQRkYXR9ua5Nhw
types:
- locality
- political
cache_hit:
Prince Rupert BC: !ruby/object:Geocoder::Result::Google
data:
address_components:
- long_name: Prince Rupert
short_name: Prince Rupert
types:
- locality
- political
- long_name: Skeena-Queen Charlotte
short_name: Skeena-Queen Charlotte
types:
- administrative_area_level_2
- political
- long_name: British Columbia
short_name: BC
types:
- administrative_area_level_1
- political
- long_name: Canada
short_name: CA
types:
- country
- political
formatted_address: Prince Rupert, BC, Canada
geometry:
bounds:
northeast:
lat: 54.338083
lng: -130.2437961
southwest:
lat: 54.19392
lng: -130.3634291
location:
lat: 54.3150367
lng: -130.3208187
location_type: APPROXIMATE
viewport:
northeast:
lat: 54.3343706
lng: -130.2478032
southwest:
lat: 54.202669
lng: -130.3608029
place_id: ChIJaUV_axPVclQRElbZTQ_jB3E
types:
- locality
- political
cache_hit:
Regina, SK: !ruby/object:Geocoder::Result::Google
data:
address_components:
- long_name: Regina
short_name: Regina
types:
- locality
- political
- long_name: Sherwood No. 159
short_name: Sherwood No. 159
types:
- administrative_area_level_3
- political
- long_name: Division No. 6
short_name: Division No. 6
types:
- administrative_area_level_2
- political
- long_name: Saskatchewan
short_name: SK
types:
- administrative_area_level_1
- political
- long_name: Canada
short_name: CA
types:
- country
- political
formatted_address: Regina, SK, Canada
geometry:
bounds:
northeast:
lat: 50.5207396
lng: -104.4924259
southwest:
lat: 50.3964489
lng: -104.7783923
location:
lat: 50.4452112
lng: -104.6188944
location_type: APPROXIMATE
viewport:
northeast:
lat: 50.5207396
lng: -104.4924259
southwest:
lat: 50.3964489
lng: -104.7783923
place_id: ChIJ6z2l-0AeHFMRsVR7t5YySjU
types:
- locality
- political
cache_hit:
Edmundston, NB: !ruby/object:Geocoder::Result::Google
data:
address_components:
- long_name: Edmundston
short_name: Edmundston
types:
- locality
- political
- long_name: Madawaska County
short_name: Madawaska County
types:
- administrative_area_level_2
- political
@@ -76,28 +375,128 @@
types:
- country
- political
formatted_address: Sackville, NB, Canada
formatted_address: Edmundston, NB, Canada
geometry:
bounds:
northeast:
lat: 45.96934
lng: -64.31372929999999
lat: 47.456634
lng: -68.14554509999999
southwest:
lat: 45.86707
lng: -64.4562439
lat: 47.3177789
lng: -68.44122399999999
location:
lat: 45.897903
lng: -64.3682803
lat: 47.3690127
lng: -68.32667409999999
location_type: APPROXIMATE
viewport:
northeast:
lat: 45.96934
lng: -64.31372929999999
lat: 47.456634
lng: -68.14554509999999
southwest:
lat: 45.86707
lng: -64.4562439
partial_match: true
place_id: ChIJA-OnietQX0sR3kWeYPsw4gs
lat: 47.3183866
lng: -68.44122399999999
place_id: ChIJuQPKxpipvUwRtNjzmeech34
types:
- locality
- political
cache_hit:
Souris, MB: !ruby/object:Geocoder::Result::Google
data:
address_components:
- long_name: Souris
short_name: Souris
types:
- locality
- political
- long_name: Glenwood
short_name: Glenwood
types:
- administrative_area_level_3
- political
- long_name: Division No. 7
short_name: Division No. 7
types:
- administrative_area_level_2
- political
- long_name: Manitoba
short_name: MB
types:
- administrative_area_level_1
- political
- long_name: Canada
short_name: CA
types:
- country
- political
- long_name: R0K
short_name: R0K
types:
- postal_code
- postal_code_prefix
formatted_address: Souris, MB R0K, Canada
geometry:
bounds:
northeast:
lat: 49.6272052
lng: -100.2464522
southwest:
lat: 49.6061908
lng: -100.2774639
location:
lat: 49.6207985
lng: -100.2583026
location_type: APPROXIMATE
viewport:
northeast:
lat: 49.6272052
lng: -100.2464522
southwest:
lat: 49.6061908
lng: -100.2774639
place_id: ChIJjVrTVVh851IRLuGKzGdiUj8
types:
- locality
- political
cache_hit:
Eldorado, MX: !ruby/object:Geocoder::Result::Google
data:
address_components:
- long_name: Eldorado
short_name: Eldorado
types:
- locality
- political
- long_name: Sinaloa
short_name: Sin.
types:
- administrative_area_level_1
- political
- long_name: Mexico
short_name: MX
types:
- country
- political
formatted_address: Eldorado, Sin., Mexico
geometry:
bounds:
northeast:
lat: 24.3379838
lng: -107.3476352
southwest:
lat: 24.3108689
lng: -107.3831387
location:
lat: 24.3240714
lng: -107.3584174
location_type: APPROXIMATE
viewport:
northeast:
lat: 24.3379838
lng: -107.3476352
southwest:
lat: 24.3108689
lng: -107.3831387
place_id: ChIJv33Pqm0ho4YRUQ45wKAluZ4
types:
- locality
- political
+27 -26
View File
@@ -1,34 +1,35 @@
module NavigationHelpers
def path_to(path)
path = path.to_sym
def path_to(path)
path = path.to_sym
args = []
case path
when /^landing$/i
path = :home
when /^registration$/i
path = "/conferences/#{@last_conference.slug}/register/"
when /^edit conference$/i
path = "/conferences/#{@last_conference.slug}/edit/"
when /^(workshops|stats|broadcast)$/i
path = "/conferences/#{@last_conference.slug}/#{path}/"
when /^(stats.xls)$/i
path = "/conferences/#{@last_conference.slug}/stats.xls"
end
case path
when /^landing$/i
path = :home
when /^(my )?workshop$/i
path = :view_workshop
args << TestState.last_conference.slug
args << TestState.last_workshop.id
when /^registration$/i
path = :register
args << TestState.last_conference.slug
when /^(conference|register|workshops)$/i
args << TestState.last_conference.slug
when /^confirm(ation)?$/
path = :confirm
args << TestState.last_token
when /^google maps$/
path = /^https:\/\/www\.google\.com\/maps\/place\/.*/
end
if path.is_a?(Symbol)
begin
path = Rails.application.routes.url_helpers.send("#{path}_path".to_sym)
rescue Object => e
raise "Can't find mapping from \"#{path}\" to a path."
end
end
if path.is_a?(Symbol)
path = Rails.application.routes.url_helpers.send("#{path}_path".to_sym, *args)
end
if path.blank?
raise "Can't find mapping from \"#{page_name}\" to a path."
end
raise "Can't find mapping from \"#{path}\" to a path." unless path.present?
return path
end
return path
end
end
World(NavigationHelpers)
+112
View File
@@ -0,0 +1,112 @@
module TestState
class Store
attr_accessor :last_email_entered
attr_accessor :last_conference
attr_accessor :last_registration
attr_accessor :last_organization
attr_accessor :last_email
attr_accessor :it
def my_account=(user)
@my_account = user
end
def my_account
@my_account ||= User.find_by(email: last_email_entered)
end
def my_registration=(reg)
@my_registration = reg
end
def my_registration
@my_registration ||= ConferenceRegistration.find_by(user_id: my_account.id)
end
def last_token=(token)
@last_token = token
end
def last_token
@last_token ||= EmailConfirmation.where(user_id: my_account.id).last.token
end
def last_workshop=(workshop)
@last_workshop = workshop
end
def last_workshop
@last_workshop ||= Workshop.all.last
end
end
module Values
class << self
def []=(key, value)
@my_values ||= {}
@my_values[key.to_sym] = value
end
def [](key)
@my_values ||= {}
return @my_values[key.to_sym]
end
end
end
module Users
class << self
def []=(username, user)
@users ||= {}
@users[username.to_s] = user
end
def [](username)
@users ||= {}
return @users[username.to_s]
end
end
end
class Sample
def self.[](type)
@types ||= {}
@types[type.to_sym] ||= Sample.new(type)
return @types[type.to_sym]
end
def method_missing(method_sym, *arguments, &block)
@arrays ||= {}
unless @arrays[method_sym].present?
@arrays[method_sym] = {
array: Object.const_get(@type.to_s.camelize).send(method_sym, *arguments, &block)
}
end
if @arrays[method_sym][:last].present?
@arrays[method_sym][:last] += 1
@arrays[method_sym][:last] = 0 if @arrays[method_sym][:last] >= @arrays[method_sym][:array].length
else
@arrays[method_sym][:last] = 0
end
return @arrays[method_sym][:array][@arrays[method_sym][:last]]
end
private
def initialize(type)
@type = type
end
end
class << self
def reset!
@store = nil
end
def method_missing(method_sym, *arguments, &block)
@store ||= Store.new
@store.send(method_sym, *arguments, &block)
end
end
end