Sync with latest simply_stored

This commit is contained in:
2015-07-22 17:21:41 +02:00
parent 49b61a5026
commit f7aa44ae2e
8 changed files with 115 additions and 21 deletions
@@ -0,0 +1,21 @@
require 'spec_helper'
feature 'Page preview' do
context 'with logged in user' do
background do
create_user 'test@example.com'
login_as 'test@example.com'
end
context 'with pages' do
background do
@page = create :page, name: 'nl1', locale: 'nl'
end
scenario 'see both languages', js: true do
visit "/cmtool/pages/#{@page.id}"
end
end
end
end
+4 -1
View File
@@ -5,6 +5,7 @@ require File.expand_path("../dummy/config/environment.rb", __FILE__)
require 'rspec/rails'
require 'factory_girl'
require 'capybara/rspec'
require 'capybara/poltergeist'
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
# Requires supporting ruby files with custom matchers and macros, etc,
@@ -14,7 +15,8 @@ Dir[File.join(ENGINE_RAILS_ROOT, "spec/factories/**/*.rb")].each {|f| require f
I18n.locale = :en
Devise.stretches = 1
#Capybara.default_driver = :selenium
Capybara.javascript_driver = :poltergeist
RSpec.configure do |config|
config.mock_with :rspec
config.include FactoryGirl::Syntax::Methods
@@ -23,6 +25,7 @@ RSpec.configure do |config|
config.include Cmtool::Engine.routes.url_helpers
config.include Devise::TestHelpers, type: :controller
config.include FeatureHelpers, type: :feature
config.include JsHelpers, type: :feature
#config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = true
config.render_views = true
+2 -2
View File
@@ -6,8 +6,8 @@ module FeatureHelpers
def login_as(email)
visit "/users/sign_in"
fill_in "user_email", with: email
fill_in "user_password", with: "secret"
find("#user_email").set email
find("#user_password").set "secret"
submit_form
end
+66
View File
@@ -0,0 +1,66 @@
module JsHelpers
def js_set_date(selector, value = '')
js_set_field selector, value
end
def js_set_field(selector, value = '')
find selector
page.execute_script("$('#{selector}').val('#{value}')")
end
def toggle_optional_input_for(attr)
js_click ".optional-input-activator-container.#{attr} .optional-input-activator-toggle"
end
def toggle_optional_text_field_for(attr)
js_click ".optional-text-field-activator-container.#{attr} .optional-input-activator-toggle"
end
def set_optional_value(attr, value='')
selector = ".optional-attribute-container.#{attr} input"
find selector
js_set_field selector, value
end
# Activate the boolean checkbox
def toggle_optional_boolean_activator_for(attr)
js_click ".optional-attribute-container.optional-boolean.#{attr} .optional-boolean-activator-toggle"
end
# Check the boolean checkbox
def toggle_optional_boolean_for(attr)
selector = ".optional-attribute-container.optional-boolean.#{attr} .optional-boolean-toggle"
js_click selector
end
# Trigger a click event through javascript. Use this to avoid waiting for
# javascript events issues
def js_click(selector)
find(selector) # wait for the page to contain the selector
page.execute_script("$('#{selector}').click()")
# wait for triggered ajax requests to be finished
steps = 0
while page.evaluate_script('$.active').to_i > 0 and steps < 25
sleep 0.1
steps += 1
end
end
def expect_path_bo_be(path)
steps = 0
while page.current_path != path and steps < 15
sleep 0.1
steps += 1
end
expect( page.current_path ).to eq path
end
# Wait for the database to have finished the update stuff, then reload
# the models. Threading might give inconsistent data
def reload_model(*models)
models.each &:reload
end
alias_method :reload_models, :reload_model
end