From aef6b6f1f8091ead818d95e73ef8df2d40e9d4f4 Mon Sep 17 00:00:00 2001 From: Rasmus Kjellberg <2277443+kjellberg@users.noreply.github.com> Date: Mon, 10 Jun 2024 12:46:47 +0200 Subject: [PATCH] test: copy helpers test --- Gemfile | 3 +-- test/helpers/.keep | 0 test/helpers/kiqr/current_helper_test.rb | 32 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test/helpers/.keep create mode 100644 test/helpers/kiqr/current_helper_test.rb diff --git a/Gemfile b/Gemfile index d21c87c..f4b8aae 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,6 @@ gem "sprockets-rails" # Start debugger with binding.b [https://github.com/ruby/debug] # gem "debug", ">= 1.0.0" - group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem # gem "brakeman", "~> 6.1" @@ -22,7 +21,7 @@ group :development, :test do # Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/] gem "rubocop-rails-omakase", require: false - gem 'rails-controller-testing' + gem "rails-controller-testing" # gem "standard", require: false # gem "erb_lint", require: false diff --git a/test/helpers/.keep b/test/helpers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/helpers/kiqr/current_helper_test.rb b/test/helpers/kiqr/current_helper_test.rb new file mode 100644 index 0000000..f562851 --- /dev/null +++ b/test/helpers/kiqr/current_helper_test.rb @@ -0,0 +1,32 @@ +require "test_helper" + +class Kiqr::CurrentHelperTest < ActionView::TestCase + attr_reader :current_user + + setup do + @current_user = create(:user) + @team_account = create(:account, name: "Company 1") + @alien_account = create(:account, name: "Someone else's account") + @current_user.account_users << AccountUser.new(account: @team_account, owner: true) + + Current.user = @current_user + end + + test "current_account returns the personal account by default" do + assert_equal @current_user.personal_account, current_account + end + + test "current_account can be a team account" do + Current.account = @team_account + assert_equal @team_account, current_account + end + + test "current_account can't be another users account" do + assert_raise { Current.account = @alien_account } + end + + test "personal_account is always the users personal account" do + Current.account = @team_account + assert_equal @current_user.personal_account, personal_account + end +end