diff --git a/.gitignore b/.gitignore index d6de502f..9c6b8b7b 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,5 @@ /app/assets/builds/* !/app/assets/builds/.keep + +/spec/support/results.txt diff --git a/.rubocop.yml b/.rubocop.yml index 99608566..17f94377 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -25,6 +25,7 @@ Lint/Env: - "**/*.rb" Exclude: - "**/config/environments/**/*" + - "**/config/initializers/**/*" - "**/config/application.rb" - "**/config/environment.rb" - "**/config/puma.rb" diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 01d0fada..9804d3b0 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,6 +1,6 @@ class PostsController < ApplicationController def index - @feed = Feed.find_by_token(params[:feed_id]) + @feed = Feed.find_by(token: params[:feed_id]) @posts = @feed.posts end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 08dfd737..6240f789 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -21,7 +21,7 @@ def sharing_meta_tags(title: "Feed Your Email") tag.meta(property: "twitter:creator", content: "@indirect"), # Icons tag.link(rel: "icon", type: "image/svg+xml", href: "/favicon.svg"), - tag.link(rel: "alternate icon", href: "/favicon.ico"), - ].join("\n").html_safe + tag.link(rel: "alternate icon", href: "/favicon.ico") + ].join("\n").html_safe # rubocop:disable Rails/OutputSafety end end diff --git a/app/processors/email_processor.rb b/app/processors/email_processor.rb index 83f1fd58..fc342a0a 100644 --- a/app/processors/email_processor.rb +++ b/app/processors/email_processor.rb @@ -1,4 +1,6 @@ class EmailProcessor + cattr_accessor :default_to_newest_feed, default: false + def initialize(email) @email = email end @@ -11,7 +13,7 @@ def process(token: nil) def feed @feed ||= Feed.where(token: feed_token).first - @feed ||= Feed.order(:updated_at).last if Rails.env.development? + @feed ||= Feed.order(:updated_at).last if default_to_newest_feed end def feed_token diff --git a/config/environments/development.rb b/config/environments/development.rb index 8fa7d269..4c6d0ece 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -19,7 +19,7 @@ # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - if Rails.root.join("tmp/caching-dev.txt").exist? + if Rails.root.join("tmp", "caching-dev.txt").exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true diff --git a/config/environments/production.rb b/config/environments/production.rb index 42013d2a..a1fac31b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -83,7 +83,7 @@ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) + logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end diff --git a/config/initializers/email_processor.rb b/config/initializers/email_processor.rb new file mode 100644 index 00000000..ff2bf474 --- /dev/null +++ b/config/initializers/email_processor.rb @@ -0,0 +1,3 @@ +Rails.application.config.to_prepare do + EmailProcessor.default_to_newest_feed = Rails.env.development? +end diff --git a/config/puma.rb b/config/puma.rb index daaf0369..ce4878f4 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -4,7 +4,7 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5) min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } threads min_threads_count, max_threads_count @@ -15,7 +15,7 @@ # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch("PORT", 3000) # Specifies the `environment` that Puma will run in. # diff --git a/db/migrate/20220111070447_add_token_to_post.rb b/db/migrate/20220111070447_add_token_to_post.rb index b85c700e..d8b1e747 100644 --- a/db/migrate/20220111070447_add_token_to_post.rb +++ b/db/migrate/20220111070447_add_token_to_post.rb @@ -1,5 +1,5 @@ class AddTokenToPost < ActiveRecord::Migration[7.0] def change - add_column :posts, :token, :citext, null: false, unique: true + add_column :posts, :token, :citext, null: false, unique: true, default: "" end end diff --git a/db/seeds.rb b/db/seeds.rb index 77b2f73b..b0a984bb 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -6,9 +6,9 @@ # movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) # Character.create(name: "Luke", movie: movies.first) -feed = Feed.find_or_create_by!(token: "somefeed", name: "Money Stuff") +Feed.find_or_create_by!(token: "somefeed", name: "Money Stuff") -json = JSON.parse(Rails.root.join("spec/support/body.json").read) +json = JSON.parse(Rails.root.join("spec", "support", "body.json").read) params = Griddler::Postmark::Adapter.normalize_params(json.deep_symbolize_keys) email = Griddler::Email.new(params) EmailProcessor.new(email).process(token: "somepost") diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 00345af7..d761692a 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,10 +1,10 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' -require 'spec_helper' -ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../config/environment', __dir__) +require "spec_helper" +ENV["RAILS_ENV"] ||= "test" +require File.expand_path("../config/environment", __dir__) # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? -require 'rspec/rails' +require "rspec/rails" # Add additional requires below this line. Rails is not loaded until this point! # Requires supporting ruby files with custom matchers and macros, etc, in diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ce33d66d..33e57b74 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,83 +14,22 @@ # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| - # rspec-expectations config goes here. You can use an alternate - # assertion/expectation library such as wrong or the stdlib/minitest - # assertions if you prefer. config.expect_with :rspec do |expectations| - # This option will default to `true` in RSpec 4. It makes the `description` - # and `failure_message` of custom matchers include text for helper methods - # defined using `chain`, e.g.: - # be_bigger_than(2).and_smaller_than(4).description - # # => "be bigger than 2 and smaller than 4" - # ...rather than: - # # => "be bigger than 2" expectations.include_chain_clauses_in_custom_matcher_descriptions = true end - # rspec-mocks config goes here. You can use an alternate test double - # library (such as bogus or mocha) by changing the `mock_with` option here. config.mock_with :rspec do |mocks| - # Prevents you from mocking or stubbing a method that does not exist on - # a real object. This is generally recommended, and will default to - # `true` in RSpec 4. mocks.verify_partial_doubles = true end - # This option will default to `:apply_to_host_groups` in RSpec 4 (and will - # have no way to turn it off -- the option exists only for backwards - # compatibility in RSpec 3). It causes shared context metadata to be - # inherited by the metadata hash of host groups and examples, rather than - # triggering implicit auto-inclusion in groups with matching metadata. config.shared_context_metadata_behavior = :apply_to_host_groups - -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # This allows you to limit a spec run to individual examples or groups - # you care about by tagging them with `:focus` metadata. When nothing - # is tagged with `:focus`, all examples get run. RSpec also provides - # aliases for `it`, `describe`, and `context` that include `:focus` - # metadata: `fit`, `fdescribe` and `fcontext`, respectively. config.filter_run_when_matching :focus - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ - # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.example_status_persistence_file_path = "spec/support/results.txt" config.disable_monkey_patching! - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). config.default_formatter = "doc" end - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. Kernel.srand config.seed -=end end