summaryrefslogtreecommitdiff
path: root/test/support
diff options
context:
space:
mode:
Diffstat (limited to 'test/support')
-rw-r--r--test/support/api_controller_test.rb29
-rw-r--r--test/support/api_integration_test.rb14
-rw-r--r--test/support/assert_responses.rb13
-rw-r--r--test/support/browser_integration_test.rb40
-rw-r--r--test/support/record_assertions.rb10
5 files changed, 70 insertions, 36 deletions
diff --git a/test/support/api_controller_test.rb b/test/support/api_controller_test.rb
new file mode 100644
index 0000000..97d86fc
--- /dev/null
+++ b/test/support/api_controller_test.rb
@@ -0,0 +1,29 @@
+class ApiControllerTest < ActionController::TestCase
+
+ def api_get(*args)
+ get *add_api_defaults(args)
+ end
+
+ def api_post(*args)
+ post *add_api_defaults(args)
+ end
+
+ def api_delete(*args)
+ delete *add_api_defaults(args)
+ end
+
+ def api_put(*args)
+ put *add_api_defaults(args)
+ end
+
+ def add_api_defaults(args)
+ add_defaults args, version: '2', format: :json
+ end
+
+ def add_defaults(args, defaults)
+ opts = args.extract_options!
+ opts.reverse_merge! defaults
+ args << opts
+ args
+ end
+end
diff --git a/test/support/api_integration_test.rb b/test/support/api_integration_test.rb
index 3b3481b..7942558 100644
--- a/test/support/api_integration_test.rb
+++ b/test/support/api_integration_test.rb
@@ -3,13 +3,12 @@ class ApiIntegrationTest < ActionDispatch::IntegrationTest
DUMMY_TOKEN = Token.new
RACK_ENV = {'HTTP_AUTHORIZATION' => %Q(Token token="#{DUMMY_TOKEN.to_s}")}
- setup do
- @testcode = InviteCode.new
- @testcode.save!
+ def api_version
+ 2
end
def login(user = nil)
- @user ||= user ||= FactoryGirl.create(:user, :invite_code => @testcode.invite_code)
+ @user ||= user ||= create_invited_user
# DUMMY_TOKEN will be frozen. So let's use a dup
@token ||= DUMMY_TOKEN.dup
# make sure @token is up to date if it already exists
@@ -19,6 +18,13 @@ class ApiIntegrationTest < ActionDispatch::IntegrationTest
@token.save
end
+ def create_invited_user(options = {})
+ @testcode = InviteCode.new
+ @testcode.save!
+ options.reverse_merge! invite_code: @testcode.invite_code
+ FactoryGirl.create :user, options
+ end
+
teardown do
if @user && @user.persisted?
@user.destroy_identities
diff --git a/test/support/assert_responses.rb b/test/support/assert_responses.rb
index 7724fb4..6a22642 100644
--- a/test/support/assert_responses.rb
+++ b/test/support/assert_responses.rb
@@ -71,21 +71,24 @@ module AssertResponses
end
def assert_login_required
- assert_error_response :not_authorized_login, :unauthorized
+ assert_error_response :not_authorized_login,
+ status: :unauthorized
end
def assert_access_denied
- assert_error_response :not_authorized, :forbidden
+ assert_error_response :not_authorized,
+ status: :forbidden
end
- def assert_error_response(key, status=nil)
- message = I18n.t(key)
+ def assert_error_response(key, options = {})
+ status=options.delete :status
+ message = I18n.t(key, options)
if content_type == 'application/json'
status ||= :unprocessable_entity
assert_json_response('error' => key.to_s, 'message' => message)
assert_response status
else
- assert_equal({:alert => message}, flash.to_hash)
+ assert_equal({'alert' => message}, flash.to_hash)
end
end
diff --git a/test/support/browser_integration_test.rb b/test/support/browser_integration_test.rb
index 1deb8fa..1f5e3d2 100644
--- a/test/support/browser_integration_test.rb
+++ b/test/support/browser_integration_test.rb
@@ -3,10 +3,11 @@
#
# Use this class for capybara based integration tests for the ui.
#
+require 'capybara/rails'
class BrowserIntegrationTest < ActionDispatch::IntegrationTest
# let's use dom_id inorder to identify sections
- include ActionController::RecordIdentifier
+ include ActionView::RecordIdentifier
CONFIG_RU = (Rails.root + 'config.ru').to_s
OUTER_APP = Rack::Builder.parse_file(CONFIG_RU).first
@@ -28,7 +29,7 @@ class BrowserIntegrationTest < ActionDispatch::IntegrationTest
Capybara.app_host = 'http://lvh.me:3003'
Capybara.server_port = 3003
Capybara.javascript_driver = :poltergeist
- Capybara.default_wait_time = 5
+ Capybara.default_max_wait_time = 5
# Make the Capybara DSL available
include Capybara::DSL
@@ -46,32 +47,17 @@ class BrowserIntegrationTest < ActionDispatch::IntegrationTest
end
def submit_signup(username = nil, password = nil)
-
- with_config invite_required: true do
-
- username ||= "test_#{SecureRandom.urlsafe_base64}".downcase
- password ||= SecureRandom.base64
- visit '/users/new'
- fill_in 'Username', with: username
- fill_in 'Password', with: password
+ username ||= "test_#{SecureRandom.urlsafe_base64}".downcase
+ password ||= SecureRandom.base64
+ visit '/signup'
+ fill_in 'Username', with: username
+ fill_in 'Password', with: password
+ if APP_CONFIG[:invite_required]
fill_in 'Invite code', with: @testcode.invite_code
- fill_in 'Password confirmation', with: password
- click_on 'Sign Up'
- return username, password
- end
-
- with_config invite_required: false do
-
- username ||= "test_#{SecureRandom.urlsafe_base64}".downcase
- password ||= SecureRandom.base64
- visit '/users/new'
- fill_in 'Username', with: username
- fill_in 'Password', with: password
- fill_in 'Password confirmation', with: password
- click_on 'Sign Up'
- return username, password
end
-
+ fill_in 'Password confirmation', with: password
+ click_on 'Sign Up'
+ return username, password
end
# currently this only works for tests with poltergeist.
@@ -101,7 +87,7 @@ class BrowserIntegrationTest < ActionDispatch::IntegrationTest
File.open(logfile_path, 'w') do |test_log|
test_log.puts self.class.name
test_log.puts "========================="
- test_log.puts __name__
+ test_log.puts name
test_log.puts Time.now
test_log.puts current_path
test_log.puts page.status_code
diff --git a/test/support/record_assertions.rb b/test/support/record_assertions.rb
new file mode 100644
index 0000000..30b947f
--- /dev/null
+++ b/test/support/record_assertions.rb
@@ -0,0 +1,10 @@
+module RecordAssertions
+
+ def assert_error(record, options)
+ options.each do |k, v|
+ errors = record.errors[k]
+ assert_equal I18n.t("errors.messages.#{v}"), errors.first
+ end
+ end
+
+end