diff --git a/.gitignore b/.gitignore index fc2396d..d5880d0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ !/log/.keep /tmp .byebug_history - +.coverage/ # OSX files .DS_Store diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..4e33a32 --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--require spec_helper +--color +--format documentation diff --git a/.solargraph.yml b/.solargraph.yml new file mode 100644 index 0000000..de93f6a --- /dev/null +++ b/.solargraph.yml @@ -0,0 +1,16 @@ +--- +include: +- "**/*.rb" +exclude: +- spec/**/* +- test/**/* +- vendor/**/* +- ".bundle/**/*" +require: [] +domains: [] +reporters: +- rubocop +- require_not_found +require_paths: [] +plugins: [] +max_files: 5000 diff --git a/Gemfile b/Gemfile index ef80204..f357ff4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.4.3' +ruby '2.5.1' gem 'rails', '5.1.5' @@ -17,9 +17,18 @@ gem 'turbolinks' gem 'uglifier', '>= 1.3.0' group :development do - gem 'pry-byebug' gem 'spring' gem 'web-console', '~> 2.0' + gem 'solargraph' +end + +group :development, :test do + gem 'rspec-rails' + gem 'shoulda-matchers' + gem 'capybara' + gem 'factory_bot_rails' + gem 'pry-byebug' + gem 'coveralls', require: false end group :production do diff --git a/Gemfile.lock b/Gemfile.lock index d4285bf..dbc8836 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,26 +38,42 @@ GEM i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) arel (8.0.0) - autoprefixer-rails (8.6.4) + ast (2.4.1) + autoprefixer-rails (9.8.4) execjs - bcrypt (3.1.12) + backport (1.1.2) + bcrypt (3.1.13) + benchmark (0.1.0) binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) - bootstrap-sass (3.3.7) + bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) - sass (>= 3.3.4) - builder (3.2.3) - byebug (10.0.2) - carrierwave (1.2.3) - activemodel (>= 4.0.0) - activesupport (>= 4.0.0) - mime-types (>= 1.16) - chosen-rails (1.8.3) + sassc (>= 2.0.0) + builder (3.2.4) + byebug (11.1.3) + capybara (3.33.0) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (~> 1.5) + xpath (~> 3.2) + carrierwave (2.1.0) + activemodel (>= 5.0.0) + activesupport (>= 5.0.0) + addressable (~> 2.6) + image_processing (~> 1.1) + mimemagic (>= 0.3.0) + mini_mime (>= 0.1.3) + chosen-rails (1.9.0) coffee-rails (>= 3.2) railties (>= 3.0) - sass-rails (>= 3.2) - coderay (1.1.2) + sassc-rails (>= 2.1.2) + coderay (1.1.3) coffee-rails (4.2.2) coffee-script (>= 2.2.0) railties (>= 4.0.0) @@ -65,59 +81,80 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.0.5) - crass (1.0.4) + concurrent-ruby (1.1.6) + coveralls (0.8.23) + json (>= 1.8, < 3) + simplecov (~> 0.16.1) + term-ansicolor (~> 1.3) + thor (>= 0.19.4, < 2.0) + tins (~> 1.6) + crass (1.0.6) debug_inspector (0.0.3) - devise (4.4.3) + devise (4.7.2) bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (>= 4.1.0, < 6.0) + railties (>= 4.1.0) responders warden (~> 1.2.3) - erubi (1.7.1) + diff-lcs (1.4.2) + docile (1.3.2) + e2mmap (0.1.0) + erubi (1.9.0) execjs (2.7.0) - ffi (1.9.25) - globalid (0.4.1) + factory_bot (6.0.2) + activesupport (>= 5.0.0) + factory_bot_rails (6.0.0) + factory_bot (~> 6.0.0) + railties (>= 5.0.0) + ffi (1.13.1) + globalid (0.4.2) activesupport (>= 4.2.0) i18n (0.9.5) concurrent-ruby (~> 1.0) - jbuilder (2.7.0) - activesupport (>= 4.2.0) - multi_json (>= 1.2) - jquery-rails (4.3.3) + image_processing (1.11.0) + mini_magick (>= 4.9.5, < 5) + ruby-vips (>= 2.0.17, < 3) + jaro_winkler (1.5.4) + jbuilder (2.10.0) + activesupport (>= 5.0.0) + jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - loofah (2.2.2) + json (2.3.0) + loofah (2.2.3) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.7.0) + mail (2.7.1) mini_mime (>= 0.1.1) mailboxer (0.15.1) carrierwave (>= 0.5.8) rails (>= 5.0.0) - method_source (0.9.0) - mime-types (3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mini_mime (1.0.0) - mini_portile2 (2.3.0) - minitest (5.11.3) - multi_json (1.13.1) - nio4r (2.3.1) - nokogiri (1.8.3) - mini_portile2 (~> 2.3.0) + maruku (0.7.3) + method_source (1.0.0) + mimemagic (0.3.5) + mini_magick (4.10.1) + mini_mime (1.0.2) + mini_portile2 (2.4.0) + minitest (5.14.1) + nio4r (2.5.2) + nokogiri (1.10.9) + mini_portile2 (~> 2.4.0) orm_adapter (0.5.0) + parallel (1.19.2) + parser (2.7.1.4) + ast (~> 2.4.1) pg (0.21.0) - pry (0.11.3) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - pry-byebug (3.6.0) - byebug (~> 10.0) - pry (~> 0.10) - puma (3.11.4) - rack (2.0.5) - rack-test (1.0.0) + pry (0.13.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.9.0) + byebug (~> 11.0) + pry (~> 0.13.0) + public_suffix (4.0.5) + puma (3.12.6) + rack (2.2.3) + rack-test (1.1.0) rack (>= 1.0, < 3) rails (5.1.5) actioncable (= 5.1.5) @@ -147,14 +184,50 @@ GEM method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + rainbow (3.0.0) rake (11.3.0) - rb-fsevent (0.10.3) - rb-inotify (0.9.10) - ffi (>= 0.5.0, < 2) - responders (2.4.0) - actionpack (>= 4.2.0, < 5.3) - railties (>= 4.2.0, < 5.3) - sass (3.5.6) + rb-fsevent (0.10.4) + rb-inotify (0.10.1) + ffi (~> 1.0) + regexp_parser (1.7.1) + responders (3.0.1) + actionpack (>= 5.0) + railties (>= 5.0) + reverse_markdown (2.0.0) + nokogiri + rexml (3.2.4) + rspec-core (3.9.2) + rspec-support (~> 3.9.3) + rspec-expectations (3.9.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-rails (4.0.1) + actionpack (>= 4.2) + activesupport (>= 4.2) + railties (>= 4.2) + rspec-core (~> 3.9) + rspec-expectations (~> 3.9) + rspec-mocks (~> 3.9) + rspec-support (~> 3.9) + rspec-support (3.9.3) + rubocop (0.86.0) + parallel (~> 1.10) + parser (>= 2.7.0.1) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.7) + rexml + rubocop-ast (>= 0.0.3, < 1.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 2.0) + rubocop-ast (0.1.0) + parser (>= 2.7.0.1) + ruby-progressbar (1.10.1) + ruby-vips (2.0.17) + ffi (~> 1.9) + sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) @@ -165,8 +238,36 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - spring (2.0.2) - activesupport (>= 4.2) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + shoulda-matchers (4.3.0) + activesupport (>= 4.2.0) + simplecov (0.16.1) + docile (~> 1.1) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + solargraph (0.39.8) + backport (~> 1.1) + benchmark + bundler (>= 1.17.2) + e2mmap + jaro_winkler (~> 1.5) + maruku (~> 0.7, >= 0.7.3) + nokogiri (~> 1.9, >= 1.9.1) + parser (~> 2.3) + reverse_markdown (>= 1.0.5, < 3) + rubocop (~> 0.52) + thor (~> 1.0) + tilt (~> 2.0) + yard (~> 0.9, >= 0.9.24) + spring (2.1.0) sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -174,18 +275,24 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - thor (0.20.0) + sync (0.5.0) + term-ansicolor (1.7.1) + tins (~> 1.0) + thor (1.0.1) thread_safe (0.3.6) - tilt (2.0.8) - turbolinks (5.1.1) - turbolinks-source (~> 5.1) - turbolinks-source (5.1.0) - tzinfo (1.2.5) + tilt (2.0.10) + tins (1.25.0) + sync + turbolinks (5.2.1) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (1.2.7) thread_safe (~> 0.1) - uglifier (4.1.14) + uglifier (4.2.0) execjs (>= 0.3.0, < 3) - warden (1.2.7) - rack (>= 1.0) + unicode-display_width (1.7.0) + warden (1.2.8) + rack (>= 2.0.6) web-console (2.3.0) activemodel (>= 4.0) binding_of_caller (>= 0.7.2) @@ -193,15 +300,21 @@ GEM sprockets-rails (>= 2.0, < 4.0) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) + websocket-extensions (0.1.5) + xpath (3.2.0) + nokogiri (~> 1.8) + yard (0.9.25) PLATFORMS ruby DEPENDENCIES bootstrap-sass + capybara chosen-rails + coveralls devise + factory_bot_rails jbuilder (~> 2.0) jquery-rails loofah (~> 2.2.1) @@ -213,7 +326,10 @@ DEPENDENCIES rails-html-sanitizer (~> 1.0.4) rails_12factor rake (~> 11.1, >= 11.1.2) + rspec-rails sass-rails (~> 5.0) + shoulda-matchers + solargraph spring sprockets (~> 3.7.2) turbolinks @@ -221,7 +337,7 @@ DEPENDENCIES web-console (~> 2.0) RUBY VERSION - ruby 2.4.3p205 + ruby 2.5.1p57 BUNDLED WITH - 1.16.1 + 1.17.3 diff --git a/README.md b/README.md index 3837735..61ebc1b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ ## CA Mailboxer 2018 -Code base for week 5 challenge - Working with legacy code +Code base for week 5 challenge - Working with legacy code... diff --git a/config/application.rb b/config/application.rb index 66d7296..6fe32f3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,7 +1,6 @@ require File.expand_path('../boot', __FILE__) require "rails" -# Pick the frameworks you want: require "active_model/railtie" require "active_job/railtie" require "active_record/railtie" @@ -9,26 +8,11 @@ require "action_mailer/railtie" require "action_view/railtie" require "sprockets/railtie" -# require "rails/test_unit/railtie" -# Require the gems listed in Gemfile, including any gems -# you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module Mailboxer class Application < Rails::Application - # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. - - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de - config.action_mailer.default_url_options = { host: 'ca-mailboxer.herokuapp.com' } config.generators do |generate| diff --git a/config/routes.rb b/config/routes.rb index 1abf899..5aa915e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,13 +5,13 @@ root 'welcome#index' - # mailbox folder routes + get "mailbox/inbox" => "mailbox#inbox", as: :mailbox_inbox get "mailbox/sent" => "mailbox#sent", as: :mailbox_sent get "mailbox/trash" => "mailbox#trash", as: :mailbox_trash - # conversations + resources :conversations do member do post :reply diff --git a/coverage/.last_run.json b/coverage/.last_run.json new file mode 100644 index 0000000..8d60cae --- /dev/null +++ b/coverage/.last_run.json @@ -0,0 +1,5 @@ +{ + "result": { + "covered_percent": 34.09 + } +} diff --git a/coverage/.resultset.json b/coverage/.resultset.json new file mode 100644 index 0000000..1a06152 --- /dev/null +++ b/coverage/.resultset.json @@ -0,0 +1,159 @@ +{ + "RSpec": { + "coverage": { + "/Users/odeanecroney/Documents/craft_academy/legacy_code_june_2020/app/models/user.rb": [ + 1, + null, + null, + 1, + null, + null, + 1, + 1, + 1, + null, + 1, + null, + 1, + 0, + null, + null, + 1, + 0, + null, + null + ], + "/Users/odeanecroney/Documents/craft_academy/legacy_code_june_2020/app/models/application_record.rb": [ + 1, + 1, + null + ], + "/Users/odeanecroney/Documents/craft_academy/legacy_code_june_2020/app/helpers/application_helper.rb": [ + 1, + 1, + 4, + 1, + 0, + 3, + 0, + null, + null, + 1, + 0, + null, + null + ], + "/Users/odeanecroney/Documents/craft_academy/legacy_code_june_2020/app/helpers/mailbox_helper.rb": [ + 1, + 1, + null, + null, + 0, + null, + null + ], + "/Users/odeanecroney/Documents/craft_academy/legacy_code_june_2020/app/controllers/application_controller.rb": [ + 1, + null, + null, + 1, + null, + 1, + null, + 1, + null, + 1, + null, + 1, + 0, + null, + null, + 1, + 0, + null, + null, + 1, + null, + 1, + 15, + null, + null + ], + "/Users/odeanecroney/Documents/craft_academy/legacy_code_june_2020/app/controllers/welcome_controller.rb": [ + 1, + 1, + null, + null + ], + "/Users/odeanecroney/Documents/craft_academy/legacy_code_june_2020/app/controllers/mailbox_controller.rb": [ + 0, + 0, + null, + 0, + 0, + 0, + 0, + null, + 0, + 0, + 0, + 0, + null, + 0, + 0, + 0, + 0, + 0 + ], + "/Users/odeanecroney/Documents/craft_academy/legacy_code_june_2020/app/controllers/conversations_controller.rb": [ + 0, + 0, + null, + 0, + 0, + null, + 0, + 0, + 0, + 0, + 0, + 0, + null, + 0, + 0, + null, + 0, + 0, + null, + 0, + 0, + 0, + 0, + 0, + null, + 0, + 0, + 0, + 0, + null, + 0, + 0, + 0, + 0, + null, + 0, + null, + 0, + 0, + 0, + null, + 0, + 0, + 0, + null, + 0 + ] + }, + "timestamp": 1593330894 + } +} diff --git a/coverage/.resultset.json.lock b/coverage/.resultset.json.lock new file mode 100644 index 0000000..e69de29 diff --git a/db/migrate/20160322070219_devise_create_users.rb b/db/migrate/20160322070219_devise_create_users.rb index 2d82e68..1593436 100644 --- a/db/migrate/20160322070219_devise_create_users.rb +++ b/db/migrate/20160322070219_devise_create_users.rb @@ -1,42 +1,20 @@ -class DeviseCreateUsers < ActiveRecord::Migration +class DeviseCreateUsers < ActiveRecord::Migration[4.2] def change create_table(:users) do |t| - ## Database authenticatable t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: "" - - ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at - - ## Rememberable - t.datetime :remember_created_at - - ## Trackable + t.datetime :remember_created_at t.integer :sign_in_count, default: 0, null: false t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.inet :current_sign_in_ip t.inet :last_sign_in_ip - - ## Confirmable - # t.string :confirmation_token - # t.datetime :confirmed_at - # t.datetime :confirmation_sent_at - # t.string :unconfirmed_email # Only if using reconfirmable - - ## Lockable - # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts - # t.string :unlock_token # Only if unlock strategy is :email or :both - # t.datetime :locked_at - - t.timestamps null: false end add_index :users, :email, unique: true add_index :users, :reset_password_token, unique: true - # add_index :users, :confirmation_token, unique: true - # add_index :users, :unlock_token, unique: true end end diff --git a/db/migrate/20160322070937_add_name_to_users.rb b/db/migrate/20160322070937_add_name_to_users.rb index bac750e..627b752 100644 --- a/db/migrate/20160322070937_add_name_to_users.rb +++ b/db/migrate/20160322070937_add_name_to_users.rb @@ -1,4 +1,4 @@ -class AddNameToUsers < ActiveRecord::Migration +class AddNameToUsers < ActiveRecord::Migration[4.2] def change add_column :users, :name, :string end diff --git a/db/migrate/20160322134145_create_mailboxer.mailboxer_engine.rb b/db/migrate/20160322134145_create_mailboxer.mailboxer_engine.rb index f1153f8..6fb777d 100644 --- a/db/migrate/20160322134145_create_mailboxer.mailboxer_engine.rb +++ b/db/migrate/20160322134145_create_mailboxer.mailboxer_engine.rb @@ -1,14 +1,12 @@ -# This migration comes from mailboxer_engine (originally 20110511145103) -class CreateMailboxer < ActiveRecord::Migration +class CreateMailboxer < ActiveRecord::Migration[4.2] def self.up - #Tables - #Conversations + create_table :mailboxer_conversations do |t| t.column :subject, :string, :default => "" t.column :created_at, :datetime, :null => false t.column :updated_at, :datetime, :null => false end - #Receipts + create_table :mailboxer_receipts do |t| t.references :receiver, :polymorphic => true t.column :notification_id, :integer, :null => false @@ -19,7 +17,7 @@ def self.up t.column :created_at, :datetime, :null => false t.column :updated_at, :datetime, :null => false end - #Notifications and Messages + create_table :mailboxer_notifications do |t| t.column :type, :string t.column :body, :text @@ -37,28 +35,17 @@ def self.up end - #Indexes - #Conversations - #Receipts - add_index "mailboxer_receipts","notification_id" - #Messages + add_index "mailboxer_receipts","notification_id" add_index "mailboxer_notifications","conversation_id" - - #Foreign keys - #Conversations - #Receipts add_foreign_key "mailboxer_receipts", "mailboxer_notifications", :name => "receipts_on_notification_id", :column => "notification_id" - #Messages add_foreign_key "mailboxer_notifications", "mailboxer_conversations", :name => "notifications_on_conversation_id", :column => "conversation_id" end def self.down - #Tables + remove_foreign_key "mailboxer_receipts", :name => "receipts_on_notification_id" remove_foreign_key "mailboxer_notifications", :name => "notifications_on_conversation_id" - - #Indexes drop_table :mailboxer_receipts drop_table :mailboxer_conversations drop_table :mailboxer_notifications diff --git a/db/migrate/20160322134146_add_conversation_optout.mailboxer_engine.rb b/db/migrate/20160322134146_add_conversation_optout.mailboxer_engine.rb index c4f4555..90c1dc3 100644 --- a/db/migrate/20160322134146_add_conversation_optout.mailboxer_engine.rb +++ b/db/migrate/20160322134146_add_conversation_optout.mailboxer_engine.rb @@ -1,5 +1,4 @@ -# This migration comes from mailboxer_engine (originally 20131206080416) -class AddConversationOptout < ActiveRecord::Migration +class AddConversationOptout < ActiveRecord::Migration[4.2] def self.up create_table :mailboxer_conversation_opt_outs do |t| t.references :unsubscriber, :polymorphic => true diff --git a/db/migrate/20160322134147_add_missing_indices.mailboxer_engine.rb b/db/migrate/20160322134147_add_missing_indices.mailboxer_engine.rb index 7444271..9a3a7b4 100644 --- a/db/migrate/20160322134147_add_missing_indices.mailboxer_engine.rb +++ b/db/migrate/20160322134147_add_missing_indices.mailboxer_engine.rb @@ -1,20 +1,12 @@ -# This migration comes from mailboxer_engine (originally 20131206080417) -class AddMissingIndices < ActiveRecord::Migration +class AddMissingIndices < ActiveRecord::Migration[4.2] def change - # We'll explicitly specify its name, as the auto-generated name is too long and exceeds 63 - # characters limitation. add_index :mailboxer_conversation_opt_outs, [:unsubscriber_id, :unsubscriber_type], name: 'index_mailboxer_conversation_opt_outs_on_unsubscriber_id_type' add_index :mailboxer_conversation_opt_outs, :conversation_id - add_index :mailboxer_notifications, :type add_index :mailboxer_notifications, [:sender_id, :sender_type] - - # We'll explicitly specify its name, as the auto-generated name is too long and exceeds 63 - # characters limitation. add_index :mailboxer_notifications, [:notified_object_id, :notified_object_type], name: 'index_mailboxer_notifications_on_notified_object_id_and_type' - add_index :mailboxer_receipts, [:receiver_id, :receiver_type] end end diff --git a/db/schema.rb b/db/schema.rb index b49dd08..22fce58 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -15,72 +15,72 @@ # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - create_table "mailboxer_conversation_opt_outs", force: :cascade do |t| - t.string "unsubscriber_type" + create_table "mailboxer_conversation_opt_outs", id: :serial, force: :cascade do |t| + t.string "unsubscriber_type" t.integer "unsubscriber_id" t.integer "conversation_id" - t.index ["conversation_id"], name: "index_mailboxer_conversation_opt_outs_on_conversation_id", using: :btree - t.index ["unsubscriber_id", "unsubscriber_type"], name: "index_mailboxer_conversation_opt_outs_on_unsubscriber_id_type", using: :btree + t.index ["conversation_id"], name: "index_mailboxer_conversation_opt_outs_on_conversation_id" + t.index ["unsubscriber_id", "unsubscriber_type"], name: "index_mailboxer_conversation_opt_outs_on_unsubscriber_id_type" end - create_table "mailboxer_conversations", force: :cascade do |t| - t.string "subject", default: "" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table "mailboxer_conversations", id: :serial, force: :cascade do |t| + t.string "subject", default: "" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "mailboxer_notifications", force: :cascade do |t| - t.string "type" - t.text "body" - t.string "subject", default: "" - t.string "sender_type" - t.integer "sender_id" - t.integer "conversation_id" - t.boolean "draft", default: false - t.string "notification_code" - t.string "notified_object_type" - t.integer "notified_object_id" - t.string "attachment" - t.datetime "updated_at", null: false - t.datetime "created_at", null: false - t.boolean "global", default: false + create_table "mailboxer_notifications", id: :serial, force: :cascade do |t| + t.string "type" + t.text "body" + t.string "subject", default: "" + t.string "sender_type" + t.integer "sender_id" + t.integer "conversation_id" + t.boolean "draft", default: false + t.string "notification_code" + t.string "notified_object_type" + t.integer "notified_object_id" + t.string "attachment" + t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.boolean "global", default: false t.datetime "expires" - t.index ["conversation_id"], name: "index_mailboxer_notifications_on_conversation_id", using: :btree - t.index ["notified_object_id", "notified_object_type"], name: "index_mailboxer_notifications_on_notified_object_id_and_type", using: :btree - t.index ["sender_id", "sender_type"], name: "index_mailboxer_notifications_on_sender_id_and_sender_type", using: :btree - t.index ["type"], name: "index_mailboxer_notifications_on_type", using: :btree + t.index ["conversation_id"], name: "index_mailboxer_notifications_on_conversation_id" + t.index ["notified_object_id", "notified_object_type"], name: "index_mailboxer_notifications_on_notified_object_id_and_type" + t.index ["sender_id", "sender_type"], name: "index_mailboxer_notifications_on_sender_id_and_sender_type" + t.index ["type"], name: "index_mailboxer_notifications_on_type" end - create_table "mailboxer_receipts", force: :cascade do |t| - t.string "receiver_type" - t.integer "receiver_id" - t.integer "notification_id", null: false - t.boolean "is_read", default: false - t.boolean "trashed", default: false - t.boolean "deleted", default: false - t.string "mailbox_type", limit: 25 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["notification_id"], name: "index_mailboxer_receipts_on_notification_id", using: :btree - t.index ["receiver_id", "receiver_type"], name: "index_mailboxer_receipts_on_receiver_id_and_receiver_type", using: :btree + create_table "mailboxer_receipts", id: :serial, force: :cascade do |t| + t.string "receiver_type" + t.integer "receiver_id" + t.integer "notification_id", null: false + t.boolean "is_read", default: false + t.boolean "trashed", default: false + t.boolean "deleted", default: false + t.string "mailbox_type", limit: 25 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["notification_id"], name: "index_mailboxer_receipts_on_notification_id" + t.index ["receiver_id", "receiver_type"], name: "index_mailboxer_receipts_on_receiver_id_and_receiver_type" end - create_table "users", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + create_table "users", id: :serial, force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.inet "current_sign_in_ip" - t.inet "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "name" - t.index ["email"], name: "index_users_on_email", unique: true, using: :btree - t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree + t.inet "current_sign_in_ip" + t.inet "last_sign_in_ip" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "name" + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end add_foreign_key "mailboxer_conversation_opt_outs", "mailboxer_conversations", column: "conversation_id", name: "mb_opt_outs_on_conversations_id" diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake new file mode 100644 index 0000000..070980c --- /dev/null +++ b/lib/tasks/ci.rake @@ -0,0 +1,9 @@ +unless Rails.env.production? + require 'rspec/core/rake_task' + require 'coveralls/rake/task' + Coveralls::RakeTask.new + namespace :ci do + desc 'Run all tests and generate a merged coverage report' + task tests: [:spec, 'coveralls:push'] + end + end \ No newline at end of file diff --git a/spec/factories/user.rb b/spec/factories/user.rb new file mode 100644 index 0000000..ea4f17c --- /dev/null +++ b/spec/factories/user.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :user do + email {'user@mail.com'} + password { 'password'} + name { 'Name'} + end +end \ No newline at end of file diff --git a/spec/feature/user_can_log_in_feature_spec.rb b/spec/feature/user_can_log_in_feature_spec.rb new file mode 100644 index 0000000..37b7367 --- /dev/null +++ b/spec/feature/user_can_log_in_feature_spec.rb @@ -0,0 +1,50 @@ +require "rails_helper" + +feature 'User can log in' do + context 'Sign in to account' + before do + create(:user, email: 'user@mail.com', password: '12345678') + visit user_session_path + end + + it 'displays a log in button' do + expect(page).to have_content 'Login' + click_on 'Login' + end + + it 'displays a email form' do + expect(page).to have_content 'Email' + end + + it 'fills in email and password' do + fill_in "Email", :with => 'user@mail.com' + fill_in "Password", :with => '12345678' + click_on "Log in" + expect(page).to have_content 'Signed in successfully.' + end + + it 'If the email format is incorrect' do + fill_in 'Email', :with => '&5aygde' + fill_in 'Password', :with => '12345678' + click_on 'Log in' + expect(page).to have_content 'Invalid Email or password.' + end + + + it 'If the password is incorrect' do + fill_in 'Email', :with => 'user@mail.com' + fill_in 'Password', :with => '2234' + click_on 'Log in' + expect(page).to have_content 'Invalid Email or password.' + end + + + it 'If the password is too short' do + fill_in 'Email', :with => '&5aygde' + fill_in 'Password', :with => '123' + click_on 'Log in' + expect(page).to have_content 'Invalid Email or password.' + end +end + + diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..726eaf4 --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +RSpec.describe User, type: :model do + describe 'db table' do + it {is_expected.to have_db_column :email} + it {is_expected.to have_db_column :encrypted_password} + it {is_expected.to have_db_column :name} + end + + describe 'validations' do + it {is_expected.to validate_presence_of :email} + it {is_expected.to validate_presence_of :password} + end + + describe 'Factory' do + it 'should have valid factory' do + expect(FactoryBot.create(:user)).to be_valid + end + end +end \ No newline at end of file diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..c1b803d --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,28 @@ +require 'spec_helper' +require 'coveralls' +Coveralls.wear_merged!('rails') +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../config/environment', __dir__) + +abort("The Rails environment is running in production mode!") if Rails.env.production? +require 'rspec/rails' +begin + ActiveRecord::Migration.maintain_test_schema! +rescue ActiveRecord::PendingMigrationError => e + puts e.to_s.strip + exit 1 +end +RSpec.configure do |config| + config.fixture_path = "#{::Rails.root}/spec/fixtures" + config.use_transactional_fixtures = true + config.infer_spec_type_from_file_location! + config.filter_rails_from_backtrace! + config.include FactoryBot::Syntax::Methods + + Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + with.library :rails + end +end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..aaa615e --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,9 @@ +RSpec.configure do |config| + config.expect_with :rspec do |expectations| + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end + config.shared_context_metadata_behavior = :apply_to_host_groups +end diff --git a/spec/user_can_log_in_spec.rb b/spec/user_can_log_in_spec.rb new file mode 100644 index 0000000..107e02f --- /dev/null +++ b/spec/user_can_log_in_spec.rb @@ -0,0 +1,15 @@ +require "rails_helper" + +feature 'User can log in' do + context 'Sign in to account' + before do + visit root_path +end + + it 'displays a log in button' do + expect(page).to have_content 'Login' + click_on 'Login' + end +end + +