Module: Glib::TestHelpers

Extended by:
ActiveSupport::Concern
Defined in:
lib/glib/test_helpers.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

HOST =

The best practice is to avoid using lvh.me due to security and performance concerns.

'www.localhost:3000'

Instance Method Summary collapse

Instance Method Details

#crawl_json_pages(user, check_result: true, log_file: nil, dump_actions: false, &block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/glib/test_helpers.rb', line 39

def crawl_json_pages(user, check_result: true, log_file: nil, dump_actions: false, &block)
  __execute_crawler(user, check_result: true) do |router, http|
    path = user[:path] ? "#{user[:path]}?format=json" : '/users/me?format=json&redirect=default'
    router.host = HOST
    router.step(
      http,
      'onClick' => {
        'action' => user[:action] || 'initiate_navigation',
        'url' => user[:url] || "http://#{HOST}#{path}"
      }
    )

    if dump_actions
      csv_string = router.http_actions.map do |row|
        action, url, params = row
        [action, url, JSON.generate(params)].to_csv
      end.join
      filename = "#{user[:email]}[#{user[:device]}][#{user[:version] || 'current'}].csv"
      filepath = File.join(__crawler_log_dir, filename)
      File.write(filepath, csv_string)
    end
  end
end

#logoutObject



69
70
71
72
# File 'lib/glib/test_helpers.rb', line 69

def logout
  delete logout_url
  assert_response :success
end

#logout_urlObject



74
75
76
# File 'lib/glib/test_helpers.rb', line 74

def logout_url
  "http://#{HOST}/users/sign_out.json"
end

#response_assert_equalObject

LOG_DIR = File.expand_path(

File.join(File.dirname(__FILE__), 'integration/json_ui_crawler_test_results')

)



33
34
35
36
37
# File 'lib/glib/test_helpers.rb', line 33

def response_assert_equal
  expected = __get_previous_result_from_git
  result = __log_controller_data(response.body)
  assert_equal JSON.parse(expected), JSON.parse(result), "Result mismatch! #{__git_is_available? ? `git diff #{__controller_log_dir}/#{__controller_log_file}` : ''}"
end

#retrace_json_pages(user, guiding_routers:) ⇒ Object



63
64
65
66
67
# File 'lib/glib/test_helpers.rb', line 63

def retrace_json_pages(user, guiding_routers:)
  __execute_crawler(user, check_result: true) do |router, http|
    router.follow(http, guiding_routers)
  end
end