diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..54d9e72 Binary files /dev/null and b/.DS_Store differ diff --git a/.env b/.env deleted file mode 100644 index 70fc800..0000000 --- a/.env +++ /dev/null @@ -1,2 +0,0 @@ -ADMIN_NAME=admin -ADMIN_PASSWORD=password \ No newline at end of file diff --git a/.gitignore b/.gitignore index d1fe9dd..21473eb 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,7 @@ procoders-unit1.md # Ignore Ruby Style Guide - STYLEGUIDE.md +STYLEGUIDE.md + +# Ignore .env +.env diff --git a/app/.DS_Store b/app/.DS_Store index 24ba02c..86bde5f 100644 Binary files a/app/.DS_Store and b/app/.DS_Store differ diff --git a/app/assets/.DS_Store b/app/assets/.DS_Store index 33e632c..bf09025 100644 Binary files a/app/assets/.DS_Store and b/app/assets/.DS_Store differ diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 3d59108..59c9b2a 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -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", + ) end end end diff --git a/config/application.rb b/config/application.rb index fe89050..c94622d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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") + 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 diff --git a/config/environments/development.rb b/config/environments/development.rb index 31f7724..fff6254 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -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 diff --git a/config/environments/production.rb b/config/environments/production.rb index b169aab..0ebb64b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -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 diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index f2e0250..87dc1a9 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -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 diff --git a/spec/unit/models/articles_spec.rb b/spec/unit/models/articles_spec.rb index 9b4c1b3..ee35ec9 100644 --- a/spec/unit/models/articles_spec.rb +++ b/spec/unit/models/articles_spec.rb @@ -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 \ No newline at end of file +end