OTP_SECRET_KEY=12345678901234567890123456789012345678901e61dbd01685e96b65227a5d6c43862c477ce947bff0185ee126cd93665df878d2518d0f153b7a57e95d6a5b
RAILS_MASTER_KEY=7cf6b8faada5332a399b0beecb626565
-
+MYSQL_SOCKET=/var/lib/mysql/mysql.sock
+MYSQL_PASSWORD="" # Add your test database password if any
+MYSQL_USERNAME="arelpe_test" # Use a different username for test
+MYSQL_HOST="localhost"
+RAILS_ENV="test"
class ApplicationMailer < ActionMailer::Base
layout "mailer"
+
+ private
+
+ def format_date(date)
+ date&.strftime("%B %d, %Y")
+ end
+ helper_method :format_date
end
<li><strong>Email:</strong> <%= @user.email %></li>
<li><strong>Subscription Type:</strong> <%= @user.subscription_type %></li>
<li><strong>Payment Amount:</strong> $<%= @user.payment_amount %></li>
- <li><strong>Payment Date:</strong> <%= @user.last_payment_at.strftime("%B %d, %Y") %></li>
+ <li><strong>Payment Date:</strong> <%= format_date(@user.last_payment_at) %></li>
</ul>
-<p>Please ensure that their account is properly set up and they have access to all paid member benefits.</p>
\ No newline at end of file
+<p>Please ensure that their account is properly set up and they have access to all paid member benefits.</p>
# config.time_zone = "Central Time (US & Canada)"
config.time_zone = "Australia/Adelaide"
# config.eager_load_paths << Rails.root.join("extras")
+ config.active_support.to_time_preserves_timezone = :zone
end
end
test:
<<: *default
database: arelpe_test
- host: 127.0.0.1
production:
<<: *default
# Unlike controllers, the mailer instance doesn't have any context about the
# incoming request so you'll need to provide the :host parameter yourself.
- config.action_mailer.default_url_options = { host: "www.example.com" }
+ config.action_mailer.default_url_options = { host: "mndrdr.org" }
+
+ config.action_mailer.default_options = {
+ }
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
class PagesControllerTest < ActionDispatch::IntegrationTest
setup do
@page = pages(:about)
- sign_in users(:admin)
+ sign_in_admin # Use our new helper method
end
test "should get index" do
assert_difference("Page.count") do
post pages_url, params: {
page: {
- content: @page.content,
- slug: "#{@page.slug}-new",
- title: "#{@page.title} New",
- visibility: @page.visibility
+ title: "New Test Page",
+ content: "Test content",
+ visibility: :visible
}
}
end
assert_redirected_to page_url(Page.last)
+ assert_equal "Page was successfully created.", flash[:notice]
end
test "should show page" do
test "should update page" do
patch page_url(@page), params: {
page: {
- content: @page.content,
- slug: @page.slug,
- title: @page.title,
- visibility: @page.visibility
+ title: "Updated Title",
+ content: "Updated content",
+ visibility: :visible
}
}
assert_redirected_to page_url(@page)
+ assert_equal "Page was successfully updated.", flash[:notice]
end
test "should destroy page" do
end
assert_redirected_to pages_url
+ assert_equal "Page was successfully destroyed.", flash[:notice]
+ end
+
+ test "non-admin cannot access pages" do
+ sign_out :user
+ sign_in_regular_user
+
+ get pages_url
+ assert_redirected_to root_path
+ assert_equal "You are not authorised to access this page. If you have an account please log in first.", flash[:alert]
end
end
+# test/mailers/admin_mailer_test.rb
require "test_helper"
class AdminMailerTest < ActionMailer::TestCase
def setup
@user = users(:paid_user)
- @user.update(last_payment_at: Time.current) # Ensure we have a payment date
+ @user.update(last_payment_at: Time.current)
end
- test "new_paid_member" do
+ test "should send new paid member notification" do
mail = AdminMailer.new_paid_member(@user)
+
assert_equal "mind reader :: New Paid Member", mail.subject
- assert_equal [ENV["ADMIN_EMAIL"]], mail.to
+ assert_equal [@admin_email], mail.to
assert_match @user.email, mail.body.encoded
+ assert_match @user.last_payment_at.strftime("%B %d, %Y"), mail.body.encoded
end
- test "new_non_financial_member" do
+ test "should send new non_financial member notification" do
user = users(:regular_user)
+ user.update!(created_at: Time.current) # Ensure we have a timestamp
+
mail = AdminMailer.new_non_financial_member(user)
+
assert_equal "mind reader :: New Non-Financial Member", mail.subject
- assert_equal [ENV["ADMIN_EMAIL"]], mail.to
+ assert_equal [@admin_email], mail.to
assert_match user.email, mail.body.encoded
+ assert_match user.created_at.strftime("%B %d, %Y"), mail.body.encoded
end
end
+# test/mailers/digest_mailer_test.rb
require "test_helper"
class DigestMailerTest < ActionMailer::TestCase
- test "weekly_bookmarks_digest" do
+ test "should send weekly bookmarks digest" do
user = users(:paid_user)
bookmarks = Post.bookmarks.limit(5)
mail = DigestMailer.weekly_bookmarks_digest(user, bookmarks)
+
assert_equal "mind reader :: weekly digest", mail.subject
assert_equal [user.email], mail.to
- assert_match user.first_name, mail.body.encoded # Changed from "weekly digest"
+ assert_match user.first_name, mail.body.encoded
+
bookmarks.each do |bookmark|
assert_match bookmark.title, mail.body.encoded
end
+# test/mailers/subscription_mailer_test.rb
require "test_helper"
class SubscriptionMailerTest < ActionMailer::TestCase
- test "confirmation_email" do
+ test "should send subscription confirmation email" do
user = users(:paid_user)
amount = 10.00
support_type = "ongoing"
mail = SubscriptionMailer.confirmation_email(user, amount, support_type)
+
assert_equal "Thank you for supporting mind reader!", mail.subject
assert_equal [user.email], mail.to
+# test/mailers/welcome_mailer_test.rb
require "test_helper"
class WelcomeMailerTest < ActionMailer::TestCase
- test "welcome_email" do
+ test "should send basic welcome email" do
user = users(:regular_user)
mail = WelcomeMailer.welcome_email(user)
+
assert_equal "Welcome to mind reader", mail.subject
assert_equal [user.email], mail.to
assert_match user.first_name, mail.body.encoded
end
- test "welcome_email_for_paid_user" do
+ test "should send paid user welcome email" do
user = users(:paid_user)
mail = WelcomeMailer.welcome_email(user)
+
assert_equal "Welcome to mind reader", mail.subject
assert_equal [user.email], mail.to
ENV['RAILS_ENV'] ||= 'test'
require_relative "../config/environment"
require "rails/test_help"
-require 'devise'
+require "devise"
+
+module ActionDispatch
+ class IntegrationTest
+ include Devise::Test::IntegrationHelpers
+ include Warden::Test::Helpers
+
+ def setup
+ Warden.test_mode!
+ end
+
+ def teardown
+ Warden.test_reset!
+ end
+ end
+end
class ActiveSupport::TestCase
- include Devise::Test::IntegrationHelpers # For controller tests
- include Devise::Test::ControllerHelpers # For functional tests
+ include Devise::Test::IntegrationHelpers
+ # Run tests in parallel with specified workers
parallelize(workers: :number_of_processors)
+
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order
fixtures :all
+
+ # Add more helper methods to be used by all tests here...
+ def sign_in_admin
+ @admin = users(:admin)
+ sign_in @admin
+ end
+
+ def sign_in_regular_user
+ @user = users(:regular_user)
+ sign_in @user
+ end
+
+ def sign_in_paid_user
+ @paid_user = users(:paid_user)
+ sign_in @paid_user
+ end
end