From b566418152ae263d06ac10114b4bc9ecf384447d Mon Sep 17 00:00:00 2001 From: Alex Tharp Date: Fri, 10 Aug 2018 03:55:42 -0400 Subject: [PATCH 1/8] chore(Spec Coverage): remove deprecated Code Climate gem; 'require: false' for SimpleCov in Gemfile --- Gemfile | 3 +-- Gemfile.lock | 9 +++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index 9af65c039..c00a9ab4c 100644 --- a/Gemfile +++ b/Gemfile @@ -81,8 +81,7 @@ group :test do gem "rspec_junit_formatter" # Coverage - gem 'simplecov' - gem 'codeclimate-test-reporter' + gem 'simplecov', require: false # Capybara for feature testing, Poltergeist for PhantomJS gem 'capybara' diff --git a/Gemfile.lock b/Gemfile.lock index 8cae964a3..751074bbf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -130,8 +130,6 @@ 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) @@ -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) @@ -513,8 +511,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,7 +559,6 @@ DEPENDENCIES apollo-tracing (~> 1.6.0) byebug capybara - codeclimate-test-reporter cortex! cortex-plugins-core (~> 3.0) database_cleaner From fee8c0adfddb05b49376f446119a2bc779ba9d7d Mon Sep 17 00:00:00 2001 From: Alex Tharp Date: Fri, 10 Aug 2018 05:09:48 -0400 Subject: [PATCH 2/8] refactor(Specs): spec config cleanup; upgrade to factory_bot; remove unnecessary gems; upgrade spec-related gems; fix deprecation warnings --- CONTRIBUTING.md | 2 +- Gemfile | 11 +++-- Gemfile.lock | 80 ++++++++++++++++++------------------- spec/rails_helper.rb | 53 +++++++++++++++++++++--- spec/spec_helper.rb | 22 ++++------ spec/support/factory_bot.rb | 3 ++ 6 files changed, 102 insertions(+), 69 deletions(-) create mode 100644 spec/support/factory_bot.rb 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 c00a9ab4c..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,7 +76,6 @@ end group :test do # Rspec gem 'json_spec', '~> 1.1' - gem 'rspec-sidekiq', '~> 3.0' gem 'shoulda-matchers', '~> 3.1' gem "rspec_junit_formatter" @@ -88,14 +87,14 @@ group :test do 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 751074bbf..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) @@ -134,20 +134,20 @@ GEM 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) @@ -212,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) @@ -232,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) @@ -291,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) @@ -303,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) @@ -348,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) @@ -459,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) @@ -563,18 +562,18 @@ DEPENDENCIES 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 @@ -586,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/spec/rails_helper.rb b/spec/rails_helper.rb index bbe1ba57f..00b5c6f42 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,11 +1,25 @@ # 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' + +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 +34,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 +68,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..c7890e49c --- /dev/null +++ b/spec/support/factory_bot.rb @@ -0,0 +1,3 @@ +RSpec.configure do |config| + config.include FactoryBot::Syntax::Methods +end From 43ae3c2dd68f365a53d0602a4640c531d78251db Mon Sep 17 00:00:00 2001 From: Alex Tharp Date: Fri, 10 Aug 2018 05:30:23 -0400 Subject: [PATCH 3/8] test(Misc): initial specs --- cortex.gemspec | 1 - spec/controllers/cortex/application_controller_spec.rb | 6 ++++++ spec/dummy/.env.example | 8 ++++++-- spec/helpers/cortex/application_helper_spec.rb | 6 ++++++ spec/jobs/cortex/application_job_spec.rb | 6 ++++++ spec/mailers/cortex/application_spec.rb | 6 ++++++ spec/mailers/previews/cortex/application_preview.rb | 5 +++++ spec/models/cortex/application_record_spec.rb | 6 ++++++ 8 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 spec/controllers/cortex/application_controller_spec.rb create mode 100644 spec/helpers/cortex/application_helper_spec.rb create mode 100644 spec/jobs/cortex/application_job_spec.rb create mode 100644 spec/mailers/cortex/application_spec.rb create mode 100644 spec/mailers/previews/cortex/application_preview.rb create mode 100644 spec/models/cortex/application_record_spec.rb 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/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 From 3b7f6bce8828a21d69d96343cabf5ca3eb4f31bf Mon Sep 17 00:00:00 2001 From: Alex Tharp Date: Mon, 13 Aug 2018 02:41:30 -0400 Subject: [PATCH 4/8] fix(FactoryBot): set up for engine use --- spec/rails_helper.rb | 1 + spec/support/factory_bot.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 00b5c6f42..f5f151a56 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -12,6 +12,7 @@ require 'capybara/rspec' require 'capybara/rails' require 'capybara/poltergeist' +require 'support/factory_bot' Capybara.javascript_driver = :poltergeist diff --git a/spec/support/factory_bot.rb b/spec/support/factory_bot.rb index c7890e49c..5318f2e71 100644 --- a/spec/support/factory_bot.rb +++ b/spec/support/factory_bot.rb @@ -1,3 +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 From 9cea2fcc94355baa7fd6fb0b0872588fa03d35c9 Mon Sep 17 00:00:00 2001 From: Alex Tharp Date: Mon, 13 Aug 2018 02:42:35 -0400 Subject: [PATCH 5/8] feat(FactoryBot): initial factories --- spec/factories/contracts.rb | 6 ++++++ spec/factories/decorators.rb | 7 +++++++ spec/factories/tenants.rb | 7 +++++++ spec/factories/users.rb | 16 ++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 spec/factories/contracts.rb create mode 100644 spec/factories/decorators.rb create mode 100644 spec/factories/tenants.rb create mode 100644 spec/factories/users.rb diff --git a/spec/factories/contracts.rb b/spec/factories/contracts.rb new file mode 100644 index 000000000..955c90673 --- /dev/null +++ b/spec/factories/contracts.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :cortex_contract, class: 'Cortex::Contract' do + name 'Bogus' + 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..0c23f2150 --- /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/tenants.rb b/spec/factories/tenants.rb new file mode 100644 index 000000000..e7f07464e --- /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..1803ba944 --- /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 From 46a300b61d6f6ebdb5c3997a9abaf568a9c2f1cb Mon Sep 17 00:00:00 2001 From: Alex Tharp Date: Mon, 13 Aug 2018 02:44:00 -0400 Subject: [PATCH 6/8] test(Misc): initial model spec files --- spec/models/cortex/content_item_spec.rb | 6 ++++++ spec/models/cortex/contentable_decorator_spec.rb | 6 ++++++ spec/models/cortex/contract_spec.rb | 6 ++++++ spec/models/cortex/decorator_spec.rb | 6 ++++++ 4 files changed, 24 insertions(+) create mode 100644 spec/models/cortex/content_item_spec.rb create mode 100644 spec/models/cortex/contentable_decorator_spec.rb create mode 100644 spec/models/cortex/contract_spec.rb create mode 100644 spec/models/cortex/decorator_spec.rb 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 From ebb3d4527d835db487bf32f400ee29f0ac32eedd Mon Sep 17 00:00:00 2001 From: Alex Tharp Date: Mon, 13 Aug 2018 02:45:14 -0400 Subject: [PATCH 7/8] test(User Model): #gravatar --- spec/models/cortex/user_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 spec/models/cortex/user_spec.rb 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 From d6c15e894eba1cfc18042e65648cc9f95068c7b4 Mon Sep 17 00:00:00 2001 From: Alex Tharp Date: Mon, 13 Aug 2018 03:09:56 -0400 Subject: [PATCH 8/8] feat(FactoryBot): expand factories --- spec/factories/content_item.rb | 7 +++++++ spec/factories/content_type.rb | 8 ++++++++ spec/factories/contracts.rb | 2 +- spec/factories/decorators.rb | 2 +- spec/factories/field.rb | 15 +++++++++++++++ spec/factories/field_item.rb | 7 +++++++ spec/factories/tenants.rb | 2 +- spec/factories/users.rb | 8 ++++---- 8 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 spec/factories/content_item.rb create mode 100644 spec/factories/content_type.rb create mode 100644 spec/factories/field.rb create mode 100644 spec/factories/field_item.rb 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 index 955c90673..0cd362f70 100644 --- a/spec/factories/contracts.rb +++ b/spec/factories/contracts.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :cortex_contract, class: 'Cortex::Contract' do - name 'Bogus' + name {Faker::Lorem.word} association :tenant, factory: :cortex_tenant end end diff --git a/spec/factories/decorators.rb b/spec/factories/decorators.rb index 0c23f2150..2f3420101 100644 --- a/spec/factories/decorators.rb +++ b/spec/factories/decorators.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :cortex_decorator, class: 'Cortex::Decorator' do name 'Wizard' - data {} + 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 index e7f07464e..8511cf55f 100644 --- a/spec/factories/tenants.rb +++ b/spec/factories/tenants.rb @@ -2,6 +2,6 @@ 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) } + description {Faker::Lorem.sentence(4, false, 0)} end end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 1803ba944..18ffbb1eb 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,9 +1,9 @@ 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 } + 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