* VRFS-311 and VRFS-312; javascript-based tests

This commit is contained in:
Seth Call 2013-05-15 15:53:19 -05:00
parent 64b3d8f15c
commit 9a8e2cf22e
9 changed files with 95 additions and 42 deletions

1
.gitignore vendored
View File

@ -35,3 +35,4 @@ target
vendor/bundle
public/assets
public/uploads
/log/*.out

View File

@ -78,7 +78,7 @@ else
gem "capybara-webkit"
end
gem 'capybara-screenshot'
gem 'cucumber-rails' #, '1.3.0', :require => false
gem 'cucumber-rails', :require => false #, '1.3.0', :require => false
gem 'factory_girl_rails', '4.1.0'
gem 'database_cleaner', '0.7.0'
gem 'guard-spork', '0.3.2'

View File

@ -148,7 +148,6 @@
userMe = r;
// TODO - Setting global variable for local user.
context.JK.userMe = r;
updateAccountForms();
updateHeader();
}).fail(app.ajaxError);
}
@ -160,26 +159,6 @@
$('#header-avatar').attr('src', photoUrl);
}
function updateAccountForms() {
var idTemplate = $('#template-identity-summary').html();
var idHtml = context.JK.fillTemplate(idTemplate, userMe);
$('#identity-summary').html(idHtml);
// TODO:
// Make a thing that puts a JSON object into a form
// and fill the profile part of the form from the JSON.
// Short-term thing for now:
$('#account-identity-form input[name="email"]').val(userMe.email);
// Profile form
$('#account-profile-form input[name="name"]').val(userMe.name);
if ("instruments" in userMe) {
$.each(userMe.instruments, function() {
addInstrument(this.description, this.id);
setProficiency(this.id, this.proficiency_level);
});
}
}
this.initialize = function() {
events();

View File

@ -33,6 +33,9 @@
// _fillTemplate(template, vals);
// --> "Hey Jon"
context.JK.fillTemplate = function(template, vals) {
if(template == null) {
console.log("vals " + JSON.stringify(vals))
}
for(var val in vals)
template=template.replace(new RegExp('{'+val+'}','g'), vals[val]);
return template;

View File

@ -57,7 +57,7 @@
<div class="account-mid profile">
<div class="left small mr20" align="center">
<!-- TODO FIX avatar -->
<a href="#" class="avatar_large"><img src="images/shared/avatar_jonathon.png" width="246" height="246" /></a></div>
<a href="#" class="avatar_large"><!--<img src="images/shared/avatar_jonathon.png" width="246" height="246" />--></a></div>
<strong>Name:</strong>{name}<br />
<strong>Location:</strong>{location}<br />
<strong>Instruments:</strong> {instruments}

View File

@ -43,14 +43,9 @@ SampleApp::Application.configure do
# For testing omniauth
OmniAuth.config.test_mode = true
TEST_CONNECT_STATES = false
if defined?(TEST_CONNECT_STATES) && TEST_CONNECT_STATES
TEST_CONNECT_STATE_JS_LOG_PREFIX = '*** ASSERT'
TEST_CONNECT_STATE_JS_CONSOLE = '/tmp/jam_connect_js.out'
config.websocket_gateway_enable = true
else
config.websocket_gateway_enable = false
end
config.websocket_gateway_enable = true
config.websocket_gateway_port = 6769
config.websocket_gateway_uri = "ws://localhost:#{config.websocket_gateway_port}/websocket"
# this is totally awful and silly; the reason this exists is so that if you upload an artifact
# through jam-admin, then jam-web can point users at it. I think 99% of devs won't even see or care about this config, and 0% of users

View File

@ -2,7 +2,6 @@ require 'spec_helper'
describe "Account", :js => true, :type => :feature, :capybara_feature => true do
=begin
subject { page }
before(:all) do
@ -14,13 +13,62 @@ describe "Account", :js => true, :type => :feature, :capybara_feature => true do
UserMailer.deliveries.clear
sign_in_poltergeist user
visit "/client#/account"
puts page.html
end
let(:user) { FactoryGirl.create(:user) }
it { should have_selector('h1', text: 'my account') }
=end
describe "identity" do
before(:each) do
click_link "account-edit-identity-link"
end
it { should have_selector('h2', text: 'identity:' ) }
it { should have_selector('form#account-edit-email-form th', text: 'Update your email address:') }
it { should have_selector('form#account-edit-password-form th', text: 'Update your password:') }
describe "update email" do
before(:each) do
fill_in "account_update_email", with: "junk@jamkazam.com"
# TODO: poltergeist doesn't support window.prompt, but we are changing this soon
#prompt = page.driver.browser.switch_to.alert
#prompt.send_keys(user.password)
#prompt.accept
end
#it { should have_selector('h1', text: 'my account') }
end
describe "update password" do
describe "successfully" do
before(:each) do
fill_in "current_password", with: user.password
fill_in "password", with: user.password
fill_in "password_confirmation", with: user.password
click_link "account-edit-password-submit"
end
it { should have_selector('h1', text: 'my account') }
end
describe "unsuccessfully" do
before(:each) do
click_link "account-edit-password-submit"
end
it { should have_selector('h2', text: 'identity:') }
it { should have_selector('div.field.error input[name=current_password] ~ ul li', text: "can't be blank") }
it { should have_selector('div.field.error input[name=password] ~ ul li', text: "is too short (minimum is 6 characters)") }
it { should have_selector('div.field.error input[name=password_confirmation] ~ ul li', text: "can't be blank") }
end
end
end
end

View File

@ -25,7 +25,6 @@ include JamRuby
# put ActionMailer into test mode
ActionMailer::Base.delivery_method = :test
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
@ -35,11 +34,12 @@ Spork.prefork do
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara'
require 'capybara/rspec'
require 'capybara/poltergeist'
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, { phantomjs_logger: 'log/phantomjs.out' })
Capybara::Poltergeist::Driver.new(app, { debug: false, phantomjs_logger: File.open('log/phantomjs.out', 'w') })
end
Capybara.javascript_driver = :poltergeist
@ -80,16 +80,41 @@ Spork.prefork do
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
if defined?(TEST_CONNECT_STATES) && TEST_CONNECT_STATES
config.use_transactional_fixtures = false
else
config.use_transactional_fixtures = true
end
config.use_transactional_fixtures = false
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation, {:except => %w[instruments genres] })
end
config.before(:each) do
# DatabaseCleaner.strategy = :transaction
DatabaseCleaner.strategy = :truncation, {:except => %w[instruments genres] }
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation, {:except => %w[instruments genres] }
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
if example.metadata[:js]
sleep 0.2 # ugh. necessary though otherwise intermittent failures: http://stackoverflow.com/questions/14265983/upgrading-capybara-from-1-0-1-to-1-1-4-makes-database-cleaner-break-my-specs
end
DatabaseCleaner.clean
end
config.include Rails.application.routes.url_helpers
config.include Capybara::DSL
end
end

View File

@ -19,4 +19,6 @@ def sign_in_poltergeist(user)
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "SIGN IN"
page.driver.set_cookie(:remember_token, user.remember_token)
end