diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 76039065c..279f9aa22 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,7 +8,7 @@ unnecessary re-work if a problem and its potential solution are first discussed * Fork on Github, then clone your repo: ```sh -git clone git@github.com:your-username/cortex.git +$ git clone git@github.com:your-username/cortex.git ``` * Follow the [setup instructions][setup] diff --git a/Gemfile b/Gemfile index 9af65c039..dee7f867c 100644 --- a/Gemfile +++ b/Gemfile @@ -29,8 +29,8 @@ group :development, :test do gem 'rspec-rails' gem 'guard-rspec', require: false gem 'database_cleaner' - gem 'factory_girl_rails', '~> 4.8' # TODO: upgrade to factory_bot - gem 'faker', '~> 1.8' + gem 'factory_bot_rails', '~> 4.10' + gem 'faker', '~> 1.9' gem 'phantomjs', '~> 2.1' gem 'jasmine-rails', '~> 0.14' @@ -76,27 +76,25 @@ end group :test do # Rspec gem 'json_spec', '~> 1.1' - gem 'rspec-sidekiq', '~> 3.0' gem 'shoulda-matchers', '~> 3.1' gem "rspec_junit_formatter" # Coverage - gem 'simplecov' - gem 'codeclimate-test-reporter' + gem 'simplecov', require: false # Capybara for feature testing, Poltergeist for PhantomJS gem 'capybara' gem 'poltergeist' # Mocking/Faking - gem 'mocha', '~> 1.3', require: false + gem 'mocha', '~> 1.7', require: false gem 'timecop', '~> 0.9' gem 'email_spec' # Javascript gem 'guard-jasmine', '~> 2.1' - gem 'jasmine-core', '~> 2.8' + gem 'jasmine-core', '~> 2.99' # Data - gem 'elasticsearch-extensions', '~> 0.0.29' + gem 'elasticsearch-extensions', '~> 0.0.30' end diff --git a/Gemfile.lock b/Gemfile.lock index 8cae964a3..757aecb3e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -89,7 +89,7 @@ GEM activerecord (>= 4.0.0, < 5.3) aws-eventstream (1.0.1) aws-partitions (1.97.0) - aws-sdk-core (3.23.0) + aws-sdk-core (3.24.0) aws-eventstream (~> 1.0) aws-partitions (~> 1.0) aws-sigv4 (~> 1.0) @@ -108,7 +108,7 @@ GEM breadcrumbs_on_rails (3.0.1) builder (3.2.3) byebug (10.0.2) - capybara (3.5.0) + capybara (3.5.1) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) @@ -130,26 +130,24 @@ GEM ffi (~> 1.0, >= 1.0.11) choice (0.2.0) cliver (0.3.2) - codeclimate-test-reporter (1.0.8) - simplecov (<= 0.13) coderay (1.1.2) concurrent-ruby (1.0.5) connection_pool (2.2.2) cortex-exceptions (0.0.4) - cortex-plugins-core (3.0.0) - aws-sdk-s3 (~> 1.5) + cortex-plugins-core (3.1.0) + aws-sdk-s3 (~> 1.17) cells (~> 4.1) cells-haml (~> 0.0) cells-rails (~> 0.0) fastimage (~> 2.1) - image_optim (~> 0.25) + image_optim (~> 0.26) image_optim_pack (~> 0.5) - image_processing (~> 0.4) + image_processing (~> 1.6) jsonb_accessor (~> 1.0) mimemagic (~> 0.3) mini_magick (~> 4.8) rails (>= 5) - shrine (~> 2.7) + shrine (~> 2.11) crass (1.0.4) database_cleaner (1.7.0) debug_inspector (0.0.3) @@ -163,7 +161,7 @@ GEM responders warden (~> 1.2.3) diff-lcs (1.3) - docile (1.1.5) + docile (1.3.1) dotenv (2.5.0) dotenv-rails (2.5.0) dotenv (= 2.5.0) @@ -214,10 +212,9 @@ GEM elasticsearch-api (5.0.5) multi_json elasticsearch-dsl (0.1.6) - elasticsearch-extensions (0.0.29) + elasticsearch-extensions (0.0.30) ansi elasticsearch - ruby-prof elasticsearch-model (5.1.0) activesupport (> 3) elasticsearch (~> 5) @@ -234,10 +231,10 @@ GEM erubis (2.7.0) execjs (2.7.0) exifr (1.3.4) - factory_girl (4.9.0) + factory_bot (4.10.0) activesupport (>= 3.0.0) - factory_girl_rails (4.9.0) - factory_girl (~> 4.9.0) + factory_bot_rails (4.10.0) + factory_bot (~> 4.10.0) railties (>= 3.0.0) faker (1.9.1) i18n (>= 0.7) @@ -293,7 +290,7 @@ GEM tilt hashie (3.5.7) htmlentities (4.3.4) - i18n (1.0.1) + i18n (1.1.0) concurrent-ruby (~> 1.0) ice_nine (0.11.2) image_optim (0.26.1) @@ -305,7 +302,9 @@ GEM image_optim_pack (0.5.1) fspath (>= 2.1, < 4) image_optim (~> 0.19) - image_processing (0.11.2) + image_processing (1.6.0) + mini_magick (~> 4.0) + ruby-vips (>= 2.0.11, < 3) image_size (1.5.0) in_threads (1.5.0) jasmine (2.99.0) @@ -350,7 +349,7 @@ GEM mini_racer (0.2.0) libv8 (>= 6.3) minitest (5.11.3) - mocha (1.6.0) + mocha (1.7.0) metaclass (~> 0.0.1) multi_json (1.13.1) multipart-post (2.0.0) @@ -461,34 +460,32 @@ GEM actionpack (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3) rolify (5.2.0) - rspec (3.7.0) - rspec-core (~> 3.7.0) - rspec-expectations (~> 3.7.0) - rspec-mocks (~> 3.7.0) - rspec-core (3.7.1) - rspec-support (~> 3.7.0) - rspec-expectations (3.7.0) + rspec (3.8.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-core (3.8.0) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-mocks (3.7.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-rails (3.7.2) + rspec-support (~> 3.8.0) + rspec-rails (3.8.0) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 3.7.0) - rspec-expectations (~> 3.7.0) - rspec-mocks (~> 3.7.0) - rspec-support (~> 3.7.0) - rspec-sidekiq (3.0.3) - rspec-core (~> 3.0, >= 3.0.0) - sidekiq (>= 2.4.0) - rspec-support (3.7.1) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.0) rspec_junit_formatter (0.4.1) rspec-core (>= 2, < 4, != 2.12.0) ruby-graphviz (1.2.3) - ruby-prof (0.17.0) + ruby-vips (2.0.13) + ffi (~> 1.9) ruby_dep (1.5.0) sass (3.5.7) sass-listen (~> 4.0.0) @@ -513,8 +510,8 @@ GEM redis (>= 3.3.5, < 5) sidekiq-failures (1.0.0) sidekiq (>= 4.0.0) - simplecov (0.13.0) - docile (~> 1.1.0) + simplecov (0.16.1) + docile (~> 1.1) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) @@ -561,23 +558,22 @@ DEPENDENCIES apollo-tracing (~> 1.6.0) byebug capybara - codeclimate-test-reporter cortex! cortex-plugins-core (~> 3.0) database_cleaner dotenv-rails - elasticsearch-extensions (~> 0.0.29) + elasticsearch-extensions (~> 0.0.30) email_spec - factory_girl_rails (~> 4.8) - faker (~> 1.8) + factory_bot_rails (~> 4.10) + faker (~> 1.9) guard-jasmine (~> 2.1) guard-rspec haml (~> 5.0) - jasmine-core (~> 2.8) + jasmine-core (~> 2.99) jasmine-rails (~> 0.14) json_spec (~> 1.1) mini_racer - mocha (~> 1.3) + mocha (~> 1.7) pg (>= 0.18, < 2.0) phantomjs (~> 2.1) poltergeist @@ -589,7 +585,6 @@ DEPENDENCIES react_on_rails (= 9.0.3) redis-rails (~> 5.0) rspec-rails - rspec-sidekiq (~> 3.0) rspec_junit_formatter sass-rails (~> 5.0) shoulda-matchers (~> 3.1) diff --git a/cortex.gemspec b/cortex.gemspec index 068153cde..8fae1f290 100644 --- a/cortex.gemspec +++ b/cortex.gemspec @@ -28,7 +28,6 @@ Gem::Specification.new do |s| # Cortex-specific s.add_dependency 'cortex-exceptions', '= 0.0.4' - #s.add_dependency 'cortex-plugins-core' # TODO: this is an awkward dependency, but necessary until we clean up hardcoded references to Plugins::Core # Service Layer s.add_dependency 'dry-types', '~> 0.13.2' diff --git a/spec/controllers/cortex/application_controller_spec.rb b/spec/controllers/cortex/application_controller_spec.rb new file mode 100644 index 000000000..7ab6d12da --- /dev/null +++ b/spec/controllers/cortex/application_controller_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' + +module Cortex + RSpec.describe ApplicationController, type: :controller do + end +end diff --git a/spec/dummy/.env.example b/spec/dummy/.env.example index b49275f86..59a222de4 100644 --- a/spec/dummy/.env.example +++ b/spec/dummy/.env.example @@ -5,7 +5,11 @@ DEVISE_SECRET= # # Asset Host Configuration # + +# CDN for Asset Uploads, i.e. https://assets.cortexcms.org HOST_ALIAS= + +# CDN for Application Assets, i.e. assets.cortexcms.org ASSET_HOST_URL= # S3 @@ -65,7 +69,7 @@ QUALTRICS_ID= # # Database Configuration # -DATABASE_NAME=cortex_starter_test +#DATABASE_NAME= #DATABASE_USERNAME= #DATABASE_PASSWORD= #DATABASE_HOST= @@ -74,7 +78,7 @@ DATABASE_NAME=cortex_starter_test # # Caching # -REDIS_NAMESPACE=cortex_test +REDIS_NAMESPACE=cortex_starter_dev CACHE_URL=redis://localhost:6379/0/cache SESSION_STORE_URL=redis://localhost:6379/0/cache diff --git a/spec/factories/content_item.rb b/spec/factories/content_item.rb new file mode 100644 index 000000000..617174c26 --- /dev/null +++ b/spec/factories/content_item.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :content_item do + state {%w(draft published).sample} + association :creator, factory: :user + content_type + end +end diff --git a/spec/factories/content_type.rb b/spec/factories/content_type.rb new file mode 100644 index 000000000..80be8dd1d --- /dev/null +++ b/spec/factories/content_type.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :content_type do + name {Faker::Commerce.product_name} + contract + description {Faker::Lorem.sentence(4, false, 0)} + association :creator, factory: :user + end +end diff --git a/spec/factories/contracts.rb b/spec/factories/contracts.rb new file mode 100644 index 000000000..0cd362f70 --- /dev/null +++ b/spec/factories/contracts.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :cortex_contract, class: 'Cortex::Contract' do + name {Faker::Lorem.word} + association :tenant, factory: :cortex_tenant + end +end diff --git a/spec/factories/decorators.rb b/spec/factories/decorators.rb new file mode 100644 index 000000000..2f3420101 --- /dev/null +++ b/spec/factories/decorators.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :cortex_decorator, class: 'Cortex::Decorator' do + name 'Wizard' + data {{}} + association :tenant, factory: :cortex_tenant + end +end diff --git a/spec/factories/field.rb b/spec/factories/field.rb new file mode 100644 index 000000000..30ae4d1e1 --- /dev/null +++ b/spec/factories/field.rb @@ -0,0 +1,15 @@ +FactoryBot.define do + factory :field do + content_type + field_type {"text_field_type"} + required false + name {Faker::Lorem.word} + name_id {name.downcase} + validations {{}} + metadata {{}} + + trait :slug do + validations {{length: {maximum: 75}, presence: true, uniqueness: true}} + end + end +end diff --git a/spec/factories/field_item.rb b/spec/factories/field_item.rb new file mode 100644 index 000000000..6adb5c876 --- /dev/null +++ b/spec/factories/field_item.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :field_item do + data {{}} + field + content_item + end +end diff --git a/spec/factories/tenants.rb b/spec/factories/tenants.rb new file mode 100644 index 000000000..8511cf55f --- /dev/null +++ b/spec/factories/tenants.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :cortex_tenant, class: 'Cortex::Tenant' do + sequence(:name) {|n| "tenant #{n}"} + sequence(:name_id) {|n| "tenant_#{n}"} + description {Faker::Lorem.sentence(4, false, 0)} + end +end diff --git a/spec/factories/users.rb b/spec/factories/users.rb new file mode 100644 index 000000000..18ffbb1eb --- /dev/null +++ b/spec/factories/users.rb @@ -0,0 +1,16 @@ +FactoryBot.define do + factory :cortex_user, class: 'Cortex::User' do + firstname {Faker::Name.first_name} + lastname {Faker::Name.last_name} + email {Faker::Internet.unique.safe_email} + password {Faker::Internet.password} + + transient do + tenants_count 5 + end + + after(:create) do |user, evaluator| + create_list(:cortex_tenant, evaluator.tenants_count, users: [user], owner: user) + end + end +end diff --git a/spec/helpers/cortex/application_helper_spec.rb b/spec/helpers/cortex/application_helper_spec.rb new file mode 100644 index 000000000..7e842b78c --- /dev/null +++ b/spec/helpers/cortex/application_helper_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' + +module Cortex + RSpec.describe ApplicationHelper, type: :helper do + end +end diff --git a/spec/jobs/cortex/application_job_spec.rb b/spec/jobs/cortex/application_job_spec.rb new file mode 100644 index 000000000..bb319ecee --- /dev/null +++ b/spec/jobs/cortex/application_job_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' + +module Cortex + RSpec.describe ApplicationJob, type: :job do + end +end diff --git a/spec/mailers/cortex/application_spec.rb b/spec/mailers/cortex/application_spec.rb new file mode 100644 index 000000000..c2ceb1d77 --- /dev/null +++ b/spec/mailers/cortex/application_spec.rb @@ -0,0 +1,6 @@ +require "rails_helper" + +module Cortex + RSpec.describe ApplicationMailer, type: :mailer do + end +end diff --git a/spec/mailers/previews/cortex/application_preview.rb b/spec/mailers/previews/cortex/application_preview.rb new file mode 100644 index 000000000..6a50e126d --- /dev/null +++ b/spec/mailers/previews/cortex/application_preview.rb @@ -0,0 +1,5 @@ +module Cortex + # Preview all emails at http://localhost:3000/rails/mailers/application + class ApplicationPreview < ActionMailer::Preview + end +end diff --git a/spec/models/cortex/application_record_spec.rb b/spec/models/cortex/application_record_spec.rb new file mode 100644 index 000000000..7a439b937 --- /dev/null +++ b/spec/models/cortex/application_record_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' + +module Cortex + RSpec.describe ApplicationRecord, type: :model do + end +end diff --git a/spec/models/cortex/content_item_spec.rb b/spec/models/cortex/content_item_spec.rb new file mode 100644 index 000000000..23a7e52ab --- /dev/null +++ b/spec/models/cortex/content_item_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' + +module Cortex + RSpec.describe ContentItem, type: :model do + end +end diff --git a/spec/models/cortex/contentable_decorator_spec.rb b/spec/models/cortex/contentable_decorator_spec.rb new file mode 100644 index 000000000..45fecc111 --- /dev/null +++ b/spec/models/cortex/contentable_decorator_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' + +module Cortex + RSpec.describe ContentableDecorator, type: :model do + end +end diff --git a/spec/models/cortex/contract_spec.rb b/spec/models/cortex/contract_spec.rb new file mode 100644 index 000000000..082c1fb2d --- /dev/null +++ b/spec/models/cortex/contract_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' + +module Cortex + RSpec.describe Contract, type: :model do + end +end diff --git a/spec/models/cortex/decorator_spec.rb b/spec/models/cortex/decorator_spec.rb new file mode 100644 index 000000000..fde60be0b --- /dev/null +++ b/spec/models/cortex/decorator_spec.rb @@ -0,0 +1,6 @@ +require 'rails_helper' + +module Cortex + RSpec.describe Decorator, type: :model do + end +end diff --git a/spec/models/cortex/user_spec.rb b/spec/models/cortex/user_spec.rb new file mode 100644 index 000000000..3ff38894f --- /dev/null +++ b/spec/models/cortex/user_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +module Cortex + RSpec.describe User, type: :model do + + let (:user) { create :cortex_user } + + describe "#gravatar" do + let (:gravatar_user) { create :cortex_user, email: "test@cortexcms.org" } + + it "should return correct URI without scheme" do + expect(gravatar_user.gravatar).to eq "//www.gravatar.com/avatar/8d718f299ed398b82cd27bba96a77996" + end + end + + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index bbe1ba57f..f5f151a56 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,11 +1,26 @@ # 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', __FILE__) +require File.expand_path('../dummy/config/environment', __FILE__) # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! +require 'mocha/api' +require 'net/http' +require 'email_spec' +require 'capybara/rspec' +require 'capybara/rails' +require 'capybara/poltergeist' +require 'support/factory_bot' + +Capybara.javascript_driver = :poltergeist + +Capybara.register_driver :poltergeist do |app| + Capybara::Poltergeist::Driver.new(app, {js_errors: false}) +end + +include ActionDispatch::TestProcess # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are @@ -20,13 +35,13 @@ # directory. Alternatively, in the individual `*_spec.rb` files, manually # require only the support files necessary. # -# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } - -# Checks for pending migrations and applies them before tests are run. -# If you are not using ActiveRecord, you can remove this line. -ActiveRecord::Migration.maintain_test_schema! +Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } RSpec.configure do |config| + # Ensure that if we are running js tests, we are using latest webpack assets + # This will use the defaults of :js and :server_rendering meta tags + ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config) + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" @@ -54,4 +69,31 @@ config.filter_rails_from_backtrace! # arbitrary gems may also be filtered via: # config.filter_gems_from_backtrace("gem name") + + config.include Warden::Test::Helpers + + config.include EmailSpec::Helpers + config.include EmailSpec::Matchers + + config.include Devise::Test::ControllerHelpers, type: :controller + + config.include RSpec::Rails::RequestExampleGroup, type: :request, file_path: /spec\/api/ + + config.before(:suite) do + DatabaseCleaner.strategy = :transaction + Capybara.current_driver = Capybara.javascript_driver + DatabaseCleaner.clean_with(:truncation) + end + + config.before(:each) do + DatabaseCleaner.start + end + + config.after(:each) do + DatabaseCleaner.clean + Warden.test_reset! + end + + config.infer_base_class_for_anonymous_controllers = false + config.order = 'random' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ce33d66df..3449d9eff 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,18 +1,10 @@ -# This file was generated by the `rails generate rspec:install` command. Conventionally, all -# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. -# The generated `.rspec` file contains `--require spec_helper` which will cause -# this file to always be loaded, without a need to explicitly require it in any -# files. -# -# Given that it is always loaded, you are encouraged to keep this file as -# light-weight as possible. Requiring heavyweight dependencies from this file -# will add to the boot time of your test suite on EVERY test run, even for an -# individual file that may not need all of that loaded. Instead, consider making -# a separate helper file that requires the additional dependencies and performs -# the additional setup, and require it from the spec files that actually need -# it. -# -# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +require 'simplecov' +SimpleCov.start 'rails' do + add_filter do |source_file| + source_file.filename.include?("_spec.rb") + end +end + RSpec.configure do |config| # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest diff --git a/spec/support/factory_bot.rb b/spec/support/factory_bot.rb new file mode 100644 index 000000000..5318f2e71 --- /dev/null +++ b/spec/support/factory_bot.rb @@ -0,0 +1,8 @@ +RSpec.configure do |config| + config.include FactoryBot::Syntax::Methods + + config.before(:suite) do + FactoryBot.definition_file_paths << File.expand_path('../../factories', __FILE__) + FactoryBot.find_definitions + end +end