Updated Gems, improved quote retrieval
[smr.git] / gui / test / test_helper.rb
blob195b1fa530e3efb2ed87401df6f518f265687171
2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
7 # version.
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR.  If not, see <http://www.gnu.org/licenses/>.
16 ENV["RAILS_ENV"] = "test"
17 include ActionDispatch::TestProcess
18 require File.expand_path('../../config/environment', __FILE__)
19 require 'rails/test_help'
21 class ActiveSupport::TestCase
22     # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
23     #
24     # Note: You'll currently still have to declare fixtures explicitly in integration tests
25     # -- they do not yet inherit this setting
26     fixtures :all
28     ##
29     # seed the database, call in tests that rely on seed data
30     def smr_seed
31         assert Rails.application.load_seed, 'db:seed failed!'
32     end
34     # Add more helper methods to be used by all tests here...
36     ##
37     # log user into Smr
38     #
39     # Success should redirect us to '/' showing Assets overview as its the
40     # default page.
41     #
42     # See ActionDispatch::IntegrationTest documentation in case multiple
43     # parallel sessions are required at some point.
44     def smr_login(loginname, password)
45         post sessions_path, :login=>loginname, :password=>password
46         assert_response :redirect
47         follow_redirect!
48         assert_response :success
50         assert_equal root_path, path
51         assert_not_nil assigns(:current_user), 'login failed, no current_user'
52         assert_not_nil assigns(:assets), 'no Assets listed after login'
53         assert_not_nil assigns(:open_positions), 'no Open Positions listed after login'
54     
55         # see we are logged in as the one we think we are and got a token
56         current_user = assigns(:current_user)
57         assert_equal current_user.login, loginname
58         assert current_user.password_auth_token
59     end
61     ##
62     # evaluates SMR_ONLINE_TEST environment variable.
63     #
64     # - true          => run tests that need internet connectivity
65     # - false / unset => skip such tests
66     def smr_online_test?
67        ENV['SMR_ONLINE_TEST'] == 'true' ? true : false
68     end
69 end