Skip to content

Commit

Permalink
Merge pull request #564 from cortex-cms/topic/example-specs
Browse files Browse the repository at this point in the history
Factories + Spec Config + Example Spec
  • Loading branch information
toastercup authored Aug 14, 2018
2 parents 0d594b9 + d6c15e8 commit a49945b
Show file tree
Hide file tree
Showing 27 changed files with 267 additions and 80 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]:your-username/cortex.git
$ git clone [email protected]:your-username/cortex.git
```

* Follow the [setup instructions][setup]
Expand Down
14 changes: 6 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
89 changes: 42 additions & 47 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion cortex.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions spec/controllers/cortex/application_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'rails_helper'

module Cortex
RSpec.describe ApplicationController, type: :controller do
end
end
8 changes: 6 additions & 2 deletions spec/dummy/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,7 +69,7 @@ QUALTRICS_ID=
#
# Database Configuration
#
DATABASE_NAME=cortex_starter_test
#DATABASE_NAME=
#DATABASE_USERNAME=
#DATABASE_PASSWORD=
#DATABASE_HOST=
Expand All @@ -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

Expand Down
7 changes: 7 additions & 0 deletions spec/factories/content_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryBot.define do
factory :content_item do
state {%w(draft published).sample}
association :creator, factory: :user
content_type
end
end
8 changes: 8 additions & 0 deletions spec/factories/content_type.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions spec/factories/contracts.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions spec/factories/decorators.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryBot.define do
factory :cortex_decorator, class: 'Cortex::Decorator' do
name 'Wizard'
data {{}}
association :tenant, factory: :cortex_tenant
end
end
15 changes: 15 additions & 0 deletions spec/factories/field.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions spec/factories/field_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryBot.define do
factory :field_item do
data {{}}
field
content_item
end
end
7 changes: 7 additions & 0 deletions spec/factories/tenants.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions spec/helpers/cortex/application_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'rails_helper'

module Cortex
RSpec.describe ApplicationHelper, type: :helper do
end
end
Loading

0 comments on commit a49945b

Please sign in to comment.