web tests repaired, and one ruby test

This commit is contained in:
Seth Call 2021-02-18 20:16:14 -06:00
parent 7e8b8112a4
commit cef44bef4c
8 changed files with 27 additions and 59 deletions

View File

@ -1,6 +1,6 @@
class CreateInitStructure < ActiveRecord::Migration
def up
# this can't apply in production or staging, -- and schema.rb captures this test/dev environments
#ActiveRecord::Base.connection.execute(IO.read(File.expand_path("../../init_db.sql", __FILE__)))
ActiveRecord::Base.connection.execute(IO.read(File.expand_path("../../init_db.sql", __FILE__)))
end
end

View File

@ -4,13 +4,13 @@ module JamRuby
class TestSupport
#helper for resetting test database
#drop create and execute db migrations
#drop create and execute db migrations
def self.recreate_database
ENV['RAILS_ENV'] = 'test'
Rake.application.init
Rake.application.load_rakefile
begin
Rake::Task['db:jam_ruby:drop'].invoke
Rake::Task['db:jam_ruby:drop'].invoke
Rake::Task['db:jam_ruby:create'].invoke
Rake::Task['db:jam_ruby:migrate'].invoke
rescue ActiveRecord::NoDatabaseError
@ -23,7 +23,9 @@ module JamRuby
def self.migrate_database
ENV['RAILS_ENV'] = 'test'
Rake.application.init
# invoke init in this way; otherwise any args passed to rspec will pass through to the rake task and blow it up.
# for instance, bundle exec rspec spec/some.rb -e "specific test" will cause a weird error
Rake.application.init('rake', [])
Rake.application.load_rakefile
Rake::Task['db:jam_ruby:migrate'].invoke
end

View File

@ -61,16 +61,16 @@ describe AffiliatePartner do
FactoryGirl.create(:user, :created_at => Time.now - 6.days, :affiliate_referral_id => partner.id)
FactoryGirl.create(:user, :created_at => Time.now - 6.days, :affiliate_referral_id => partner.id)
FactoryGirl.create(:user, :created_at => Time.now - 3.days, :affiliate_referral_id => partner.id)
FactoryGirl.create(:user, :created_at => Time.now - 2.days, :affiliate_referral_id => partner.id)
recent = FactoryGirl.create(:user, :created_at => Time.now - 2.days, :affiliate_referral_id => partner.id)
partner.reload
expect(partner.referral_user_count).to eq(6)
by_date = partner.referrals_by_date
expect(by_date.count).to eq(4)
keys = by_date.keys
expect(keys.first).to eq(Date.parse((Time.now - 2.days).to_s))
expect(keys.first).to eq(Date.parse((Time.now.utc - 2.days).to_s))
expect(by_date[keys.first]).to eq(1)
expect(keys.last).to eq(Date.parse((Time.now - 7.days).to_s))
expect(keys.last).to eq(Date.parse((Time.now.utc - 7.days).to_s))
expect(by_date[keys.last]).to eq(2)
end

View File

@ -5,6 +5,10 @@
tests=(
"spec/features/signup_spec.rb"
"spec/features/signin_spec.rb"
"spec/features/affiliate_program_spec.rb"
"spec/features/affiliate_visit_tracking_spec.rb"
"spec/features/affiliate_referral_spec.rb"
"spec/controllers/api_affiliate_controller_spec.rb"
)

View File

@ -7,7 +7,6 @@ describe "Affiliate Program", :js => true, :type => :feature, :capybara_feature
let(:user) { FactoryGirl.create(:user) }
before(:each) do
User.delete_all
AffiliateQuarterlyPayment.delete_all
AffiliateMonthlyPayment.delete_all
AffiliateTrafficTotal.delete_all
@ -27,16 +26,16 @@ describe "Affiliate Program", :js => true, :type => :feature, :capybara_feature
it "logged in user creates affiliate" do
fast_signin user, '/affiliateProgram'
find('input#entity_individual').trigger(:click)
find('input#entity_individual').click
find('.agree-button').trigger(:click)
find('.agree-button').click
find('h1', text: 'congratulations')
find('.button-orange', text: 'GO TO AFFILIATE PAGE').trigger(:click)
find('.button-orange', text: 'GO TO AFFILIATE PAGE').click
find('.tab-account', text: 'So please provide this data, and be sure to keep it current!')
partner = AffiliatePartner.first
partner = AffiliatePartner.order('created_at desc').first
partner.partner_user.should eq(user)
partner.entity_type.should eq('Individual')
end
@ -44,18 +43,18 @@ describe "Affiliate Program", :js => true, :type => :feature, :capybara_feature
it "logged in user creates entity affiliate" do
fast_signin user, '/affiliateProgram'
find('input#entity_entity').trigger(:click)
find('input#entity_entity').click
fill_in('entity-name', with: 'Mr. Bubbles')
select('Sole Proprietor', from:'entity-type')
find('.agree-button').trigger(:click)
find('.agree-button').click
find('h1', text: 'congratulations')
find('.button-orange', text: 'GO TO AFFILIATE PAGE').trigger(:click)
find('.button-orange', text: 'GO TO AFFILIATE PAGE').click
find('.tab-account', text: 'So please provide this data, and be sure to keep it current!')
partner = AffiliatePartner.first
partner = AffiliatePartner.order('created_at desc').first
partner.partner_user.should eq(user)
partner.entity_type.should eq('Sole Proprietor')
end
@ -63,26 +62,25 @@ describe "Affiliate Program", :js => true, :type => :feature, :capybara_feature
it "new user creates individual affiliate" do
visit '/affiliateProgram'
find('input#entity_individual').trigger(:click)
find('input#entity_individual').click
find('.agree-button').trigger(:click)
find('.agree-button').click
find('h1', text: 'congratulations')
find('.button-orange', text: 'GO SIGNUP').trigger(:click)
find('.button-orange', text: 'GO SIGNUP').click
fill_in "jam_ruby_user[first_name]", with: "Affiliate1"
fill_in "jam_ruby_user[last_name]", with: "Someone"
fill_in "jam_ruby_user[email]", with: "affiliate1@jamkazam.com"
fill_in "jam_ruby_user[password]", with: "jam123"
fill_in "jam_ruby_user[password_confirmation]", with: "jam123"
check("jam_ruby_user[instruments][drums][selected]")
check("jam_ruby_user[terms_of_service]")
click_button "CREATE ACCOUNT"
should have_title("JamKazam | Congratulations")
found_user = User.first
partner = AffiliatePartner.first
found_user = User.order('created_at desc').first
partner = AffiliatePartner.order('created_at desc').first
partner.partner_user.should eq(found_user)
partner.entity_type.should eq('Individual')
end

View File

@ -39,7 +39,6 @@ describe "affiliate visit tracking", :js => true, :type => :feature, :capybara_
fill_in "jam_ruby_user[email]", with: "referral1@jamkazam.com"
fill_in "jam_ruby_user[password]", with: "jam123"
fill_in "jam_ruby_user[password_confirmation]", with: "jam123"
check("jam_ruby_user[instruments][drums][selected]")
check("jam_ruby_user[terms_of_service]")
click_button "CREATE ACCOUNT"

View File

@ -1,36 +0,0 @@
require 'spec_helper'
describe "affiliate visit tracking" do
subject { page }
let(:user) { FactoryGirl.create(:user) }
let(:partner) { FactoryGirl.create(:affiliate_partner) }
let(:affiliate_params) { partner.affiliate_query_params }
before(:each) do
AffiliateReferralVisit.delete_all
end
it "tracks" do
visit '/?' + affiliate_params
should_be_at_root
AffiliateReferralVisit.count.should eq(1)
visit = AffiliateReferralVisit.first
visit.visited_url.should eq('/?' + affiliate_params)
visit.affiliate_partner_id.should eq(partner.id)
visit.first_visit.should be true
download_url = '/downloads?' + affiliate_params
visit download_url
find('h2.create-account-header')
AffiliateReferralVisit.count.should eq(2)
visit = AffiliateReferralVisit.find_by_visited_url(download_url)
visit.affiliate_partner_id.should eq(partner.id)
visit.first_visit.should be false
end
end

View File

@ -175,6 +175,7 @@ end
# skip the typical login form, which redirects to /client (slow due to extra login step).
# So this just sets the cookie, and puts you where you want to be
def fast_signin(user, url)
visit '/'
set_login_cookie(user)
visit url
end