2014-05-16 18:03:13 -04:00
|
|
|
require 'test_helper'
|
2016-05-22 16:21:00 -04:00
|
|
|
require 'support/stub_site_config_helper'
|
2007-03-30 04:36:52 +00:00
|
|
|
|
2013-05-11 23:13:16 +02:00
|
|
|
class StoriesTest < ActionDispatch::IntegrationTest
|
2016-05-22 16:21:00 -04:00
|
|
|
include StubSiteConfigHelper
|
2007-03-30 04:36:52 +00:00
|
|
|
|
|
|
|
|
# ####################################################
|
|
|
|
|
# Testing login and signup by different kinds of users
|
|
|
|
|
# ####################################################
|
|
|
|
|
def test_signup_new_user_by_admin
|
|
|
|
|
admin = new_session_as(:admin_user,"abracadabra")
|
|
|
|
|
admin.goes_to_signup
|
2012-04-27 14:22:16 +02:00
|
|
|
admin.signs_up_with(:user => {:login => "newbie",
|
2007-03-30 04:36:52 +00:00
|
|
|
:password => "newbiepass",
|
|
|
|
|
:password_confirmation => "newbiepass"})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_signup_new_user_by_nonadmin
|
2016-05-22 16:21:00 -04:00
|
|
|
stub_site_config do
|
|
|
|
|
SITE_CONFIG['open_signups'] = false
|
|
|
|
|
other_user = new_session_as(:other_user,"sesame")
|
|
|
|
|
other_user.goes_to_signup_as_nonadmin
|
|
|
|
|
end
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
2012-11-29 15:09:37 -05:00
|
|
|
def test_open_signup_new_user
|
2016-05-22 16:21:00 -04:00
|
|
|
stub_site_config do
|
|
|
|
|
SITE_CONFIG['open_signups'] = true
|
|
|
|
|
get "/signup"
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_template "users/new"
|
|
|
|
|
post "/users", :user => {:login => "newbie",
|
|
|
|
|
:password => "newbiepass",
|
|
|
|
|
:password_confirmation => "newbiepass"}
|
|
|
|
|
assert_response :redirect
|
|
|
|
|
follow_redirect!
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_template "todos/index"
|
|
|
|
|
end
|
2012-11-29 15:09:37 -05:00
|
|
|
end
|
|
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
|
|
module CustomAssertions
|
|
|
|
|
|
|
|
|
|
attr_reader :user
|
|
|
|
|
|
|
|
|
|
def logs_in_as(user,plain_pass)
|
2010-09-28 17:49:08 +02:00
|
|
|
@user = user
|
2012-04-27 14:22:16 +02:00
|
|
|
post "/login", :user_login => @user.login,
|
|
|
|
|
:user_password => plain_pass,
|
2007-03-30 04:36:52 +00:00
|
|
|
:user_noexpiry => 'n'
|
|
|
|
|
assert_response :redirect
|
|
|
|
|
follow_redirect!
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_template "todos/index"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def goes_to_login
|
|
|
|
|
get "/login"
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_template "login/login"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def goes_to_signup
|
|
|
|
|
get "/signup"
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_template "users/new"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def goes_to_signup_as_nonadmin
|
|
|
|
|
get "/signup"
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_template "users/nosignup"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def signs_up_with(options)
|
|
|
|
|
post "/users", options
|
|
|
|
|
assert_response :redirect
|
|
|
|
|
follow_redirect!
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_template "todos/index"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def new_session_as(user,plainpass)
|
|
|
|
|
open_session do |sess|
|
|
|
|
|
sess.extend(CustomAssertions)
|
|
|
|
|
sess.goes_to_login
|
2010-09-28 17:49:08 +02:00
|
|
|
sess.logs_in_as(users(user),plainpass)
|
2007-03-30 04:36:52 +00:00
|
|
|
yield sess if block_given?
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-11-29 15:09:37 -05:00
|
|
|
end
|