Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 0 additions & 2 deletions .env

This file was deleted.

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@
procoders-unit1.md

# Ignore Ruby Style Guide
STYLEGUIDE.md
STYLEGUIDE.md

# Ignore .env
.env
Binary file modified app/.DS_Store
Binary file not shown.
Binary file modified app/assets/.DS_Store
Binary file not shown.
11 changes: 7 additions & 4 deletions app/mailers/notification_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
class NotificationMailer < ApplicationMailer
default from: "notifications@example.com"

def notification_email(article)
@article = article
notifications = Notification.all
notifications.each do |notification|
mail(to: notification.email, subject: "New blog post!!!")

Notification.in_batches.each_record do |notification|
mail(
to: notification.email,
subject: "Arrons blog has been updated!",
from: "arron.fletcher@shiftcommerce.com",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change this to a personal email address

)
end
end
end
15 changes: 13 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@ class Application < Rails::Application
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.
config.action_mailer.default_url_options = { host: "localhost:4000" }
config.action_mailer.asset_host = "http://localhost:4000"
config.action_mailer.default_url_options = { host: ENV.fetch("MAILER_HOST") }
config.action_mailer.asset_host = ENV.fetch("MAILER_HOST")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove all this stuff from application.rb as you are defining them in development.rb and production.rb already

config.action_mailer.delivery_method = :smtp

# implemented settings based on https://postmarkapp.com/developer/user-guide/sending-email/sending-with-smtp
config.action_mailer.smtp_settings = {
address: "smtp.postmarkapp.com",
port: 25,
user_name: ENV.fetch("SMTP_NAME"),
password: ENV.fetch("SMTP_PASSWORD"),
authentication: "plain",
enable_starttls_auto: true
}
end
end
16 changes: 15 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker


config.action_mailer.default_url_options = { host: ENV.fetch("MAILER_HOST") }
config.action_mailer.asset_host = ENV.fetch("MAILER_HOST")

# Not sure if I need this line as method already set in config/environments/development.rb
config.action_mailer.delivery_method = :smtp

# implemented settings based on https://postmarkapp.com/developer/user-guide/sending-email/sending-with-smtp
config.action_mailer.smtp_settings = {
address: "smtp.postmarkapp.com",
port: 25,
user_name: ENV.fetch("SMTP_NAME"),
password: ENV.fetch("SMTP_PASSWORD"),
authentication: "plain",
enable_starttls_auto: true
}
end
16 changes: 16 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,20 @@

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

config.action_mailer.default_url_options = { host: ENV.fetch("MAILER_HOST") }
config.action_mailer.asset_host = ENV.fetch("MAILER_HOST")

# Not sure if I need this line as method already set in config/environments/development.rb
config.action_mailer.delivery_method = :smtp

# implemented settings based on https://postmarkapp.com/developer/user-guide/sending-email/sending-with-smtp
config.action_mailer.smtp_settings = {
address: "smtp.postmarkapp.com",
port: 25,
user_name: ENV.fetch("SMTP_NAME"),
password: ENV.fetch("SMTP_PASSWORD"),
authentication: "plain",
enable_starttls_auto: true
}
end
4 changes: 2 additions & 2 deletions spec/mailers/notification_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
let(:mail) { NotificationMailer.notification_email(article) }

it "renders the headers" do
expect(mail.subject).to eq("New blog post!!!")
expect(mail.subject).to eq("Arrons blog has been updated!")
expect(mail.to).to eq([notification.email])
expect(mail.from).to eq(["notifications@example.com"])
expect(mail.from).to eq(["arron.fletcher@shiftcommerce.com"])
end

it "renders the body" do
Expand Down
43 changes: 29 additions & 14 deletions spec/unit/models/articles_spec.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
require "rails_helper"

RSpec.describe Article, :type => :model do
it "creates new article" do
expect(Article.new(title: "Testing", text: "Test" )).to be_valid
RSpec.describe Article, type: :model do
describe "creating a new valid article" do
let(:article) { build(:article) }

it "should be valid" do
expect(article).to be_valid
end
end
end

RSpec.describe Article, :type => :model do
it "wont create article because of article params" do
expect(Article.new(title: "Test", text: "Test" )).not_to be_valid
describe "creating an article" do
it "sends out an email when an article is created" do
create(:notification)
expect{create(:article)}.to change{ActionMailer::Base.deliveries.count}.by(1)
end
end
end

RSpec.describe Article, :type => :model do
it "edit article" do
@article = Article.new(title: "Testing", text:"test123")
@article.update(title: "Testing123", text: "123121231")
expect(@article).to have_attributes(title: "Testing123")
describe "creating an invalid article" do
let(:article) { build(:article, title: "Test") }

it "should be invalid" do
expect(article).not_to be_valid
end
end

describe "editing an article with valid data" do
let!(:article) { create(:article) }

it "should update" do
article.update(title: "Testing123", text: "123121231")

expect(article).to have_attributes(title: "Testing123")
end
end
end
end