Skip to content

Commit

Permalink
Yaaay, we have a working test
Browse files Browse the repository at this point in the history
  • Loading branch information
forsbergplustwo committed Aug 20, 2023
1 parent 16cac9c commit eda139b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
9 changes: 7 additions & 2 deletions app/controllers/metrics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ def set_data
end

def set_dates
@first_metric_date = current_user.oldest_metric_date
@latest_metric_date = current_user.newest_metric_date
if current_user.metrics.any?
@first_metric_date = current_user.oldest_metric_date
@latest_metric_date = current_user.newest_metric_date
else
@first_metric_date = Date.today
@latest_metric_date = Date.today
end
end

def set_app_titles
Expand Down
1 change: 1 addition & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
config.active_support.test_order = :random
end
4 changes: 1 addition & 3 deletions test/controllers/home_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require "test_helper"

class HomeControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end

end
9 changes: 6 additions & 3 deletions test/controllers/metrics_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
require "test_helper"

class MetricsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
test "should get index" do
sign_in users(:regular)

get :index
assert_response :success
end
end
8 changes: 3 additions & 5 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
regular:
email: [email protected]
encrypted_password: <%= User.new.send(:password_digest, '123greetings') %>
14 changes: 14 additions & 0 deletions test/support/rails_4_thread_error_fix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
if RUBY_VERSION>='2.6.0'
if Rails.version < '5'
class ActionController::TestResponse < ActionDispatch::TestResponse
def recycle!
# hack to avoid MonitorMixin double-initialize error:
@mon_mutex_owner_object_id = nil
@mon_mutex = nil
initialize
end
end
else
puts "Monkeypatch for ActionController::TestResponse no longer needed"
end
end
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"

# TODO: Remove this when Rails 4 is no longer supported.
require_relative "./support/rails_4_thread_error_fix"

class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
#
Expand All @@ -10,4 +13,9 @@ class ActiveSupport::TestCase
fixtures :all

# Add more helper methods to be used by all tests here...

end

class ActionController::TestCase
include Devise::TestHelpers
end

0 comments on commit eda139b

Please sign in to comment.