mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 02:56:26 -05:00
3e50313fdc
Since rspec-rails 3, the default installation creates two helper files: * `spec_helper.rb` * `rails_helper.rb` `spec_helper.rb` is intended as a way of running specs that do not require Rails, whereas `rails_helper.rb` loads Rails (as Discourse's current `spec_helper.rb` does). For more information: https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#default-helper-files In this commit, I've simply replaced all instances of `spec_helper` with `rails_helper`, and renamed the original `spec_helper.rb`. This brings the Discourse project closer to the standard usage of RSpec in a Rails app. At present, every spec relies on loading Rails, but there are likely many that don't need to. In a future pull request, I hope to introduce a separate, minimal `spec_helper.rb` which can be used in tests which don't rely on Rails.
57 lines
1.7 KiB
Ruby
57 lines
1.7 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe EmailLog do
|
|
|
|
it { is_expected.to belong_to :user }
|
|
it { is_expected.to validate_presence_of :to_address }
|
|
it { is_expected.to validate_presence_of :email_type }
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
context 'after_create' do
|
|
context 'with user' do
|
|
it 'updates the last_emailed_at value for the user' do
|
|
expect {
|
|
user.email_logs.create(email_type: 'blah', to_address: user.email)
|
|
user.reload
|
|
}.to change(user, :last_emailed_at)
|
|
end
|
|
|
|
it "doesn't update last_emailed_at if skipped is true" do
|
|
expect {
|
|
user.email_logs.create(email_type: 'blah', to_address: user.email, skipped: true)
|
|
user.reload
|
|
}.to_not change { user.last_emailed_at }
|
|
end
|
|
end
|
|
end
|
|
|
|
describe '#count_per_day' do
|
|
it "counts sent emails" do
|
|
user.email_logs.create(email_type: 'blah', to_address: user.email)
|
|
user.email_logs.create(email_type: 'blah', to_address: user.email, skipped: true)
|
|
expect(described_class.count_per_day(1.day.ago, Time.now).first[1]).to eq 1
|
|
end
|
|
end
|
|
|
|
describe ".last_sent_email_address" do
|
|
context "when user's email exist in the logs" do
|
|
before do
|
|
user.email_logs.create(email_type: 'signup', to_address: user.email)
|
|
user.email_logs.create(email_type: 'blah', to_address: user.email)
|
|
user.reload
|
|
end
|
|
|
|
it "the user's last email from the log" do
|
|
expect(user.email_logs.last_sent_email_address).to eq(user.email)
|
|
end
|
|
end
|
|
|
|
context "when user's email does not exist email logs" do
|
|
it "returns nil" do
|
|
expect(user.email_logs.last_sent_email_address).to be_nil
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|