Skip to content

Commit

Permalink
dry validation specs
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbeales committed Mar 28, 2018
1 parent bb5ff13 commit 68bca77
Show file tree
Hide file tree
Showing 30 changed files with 280 additions and 344 deletions.
88 changes: 44 additions & 44 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,58 @@

source 'https://rubygems.org'

gem 'activerecord', '~> 5.1.5' # ORM
gem 'acts-as-taggable-array-on', '~> 0.4.0', require: false # adds tags
gem 'bugsnag', '~> 6.6', require: false # online bug reporting
gem 'dotenv', '~> 2.2.1', require: false # adds environment variables from .env files
gem 'facets', '~> 3.1.0', require: false # additional core methods
gem 'i18n', '~> 0.9.5', require: false # internationalization support
gem 'jsonb_accessor', '~> 1.0.0', require: false # adds methods to access Jsonb fields
gem 'kiba', '~> 2.0.0', require: false # ETL
gem 'mobility', '~> 0.5.1', require: false # translations
gem 'multi_json', '~> 1.13.1', require: false # common interface to load json
gem 'oj', '~> 3.5.0', require: false # faster json parsing
gem 'pg', '~> 1.0.0', platform: :ruby, require: false # for Postgres
gem 'puma', '~> 3.11.2', require: false # puma web server
gem 'rack-cache', '~> 1.7.1', require: false # http caching
gem 'rack-contrib', '~> 2.0.1', require: false # browser localization
gem 'rack-heartbeat', '~> 1.1.0' # provide /heartbeat URL
gem 'rack-protection', '~> 2.0.1', require: false # protect against web attacks
gem 'rack-ssl', '~> 1.4.1', require: false # ssl for rack in production
gem 'rake', '~> 12.3.1', require: false # so we can run Rake tasks
gem 'ralyxa', '~> 1.7.0', require: false # ruby alexa framework
gem 'rest-client', '~> 2.0.2', require: false # minimum version without security vulnerabilities
gem 'route_downcaser', '~> 1.2.1', require: false # case isnensitive URLs
gem 'sinatra', '~> 2.0.1', require: false # Web server
gem 'sinatra-activerecord', '~> 2.0.13', require: false # for Active Record models
gem 'sinatra-contrib', '~> 2.0.1', require: false # hot reloading
gem 'sinatra_logger', '~> 0.1.0', require: false # for logging
gem 'turnout', '~> 2.4.1', require: false # for maintenance mode
gem 'validates_email_format_of', '~>1.6.3', require: false # validates email format
gem 'activerecord', '>= 5.1.5' # ORM
gem 'acts-as-taggable-array-on', '>= 0.4.0', require: false # adds tags
gem 'bugsnag', '>= 6.6', require: false # online bug reporting
gem 'dotenv', '>= 2.2.1', require: false # adds environment variables from .env files
gem 'facets', '>= 3.1.0', require: false # additional core methods
gem 'i18n', '>= 0.9.5', require: false # internationalization support
gem 'jsonb_accessor', '>= 1.0.0', require: false # adds methods to access Jsonb fields
gem 'kiba', '>= 2.0.0', require: false # ETL
gem 'mobility', '>= 0.5.1', require: false # translations
gem 'multi_json', '>= 1.13.1', require: false # common interface to load json
gem 'oj', '>= 3.5.0', require: false # faster json parsing
gem 'pg', '>= 1.0.0', platform: :ruby, require: false # for Postgres
gem 'puma', '>= 3.11.2', require: false # puma web server
gem 'rack-cache', '>= 1.7.1', require: false # http caching
gem 'rack-contrib', '>= 2.0.1', require: false # browser localization
gem 'rack-heartbeat', '>= 1.1.0' # provide /heartbeat URL
gem 'rack-protection', '>= 2.0.1', require: false # protect against web attacks
gem 'rack-ssl', '>= 1.4.1', require: false # ssl for rack in production
gem 'rake', '>= 12.3.1', require: false # so we can run Rake tasks
gem 'ralyxa', '>= 1.7.0', require: false # ruby alexa framework
gem 'rest-client', '>= 2.0.2', platform: :ruby, require: false # minimum version without security vulnerabilities
gem 'route_downcaser', '>= 1.2.1', require: false # case isnensitive URLs
gem 'sinatra', '>= 2.0.1', require: false # Web server
gem 'sinatra-activerecord', '>= 2.0.13', require: false # for Active Record models
gem 'sinatra-contrib', '>= 2.0.1', require: false # hot reloading
gem 'sinatra_logger', '>= 0.1.0', require: false # for logging
gem 'turnout', '>= 2.4.1', require: false # for maintenance mode
gem 'validates_email_format_of', '>= 1.6.3', require: false # validates email format

group :test do
gem 'bundler-audit', '~> 0.6.0', require: false # check gems for security issues
gem 'coveralls', '~> 0.7.1', require: false # code coverage
gem 'bundler-audit', '>= 0.6.0', require: false # check gems for security issues
gem 'coveralls', '>= 0.7.1', require: false # code coverage
gem 'database_cleaner', '=1.6.1', require: false # for test database cleaning
gem 'factory_bot', '~> 4.0', require: false # for test data setup
gem 'fuubar', '~> 2.3.1', require: false # rspec formatter
gem 'rack-test', '~> 1.0.0', require: false # for testing rake servers
gem 'rspec', '~> 3.7.0', require: false # for behavioral driven testing
gem 'rubocop', '~> 0.54.0', require: false # syntax checking
gem 'ruby_audit', '~> 1.2.0', require: false # complements bundler-audit
gem 'simplecov', '~> 0.16.1', require: false # for code coverage
gem 'timecop', '~> 0.9.1', require: false # testing time dependent
gem 'travis', '~> 1.8.8', require: false # for continuous integrations
gem 'travis_check_rubies', '~> 0.2.5', require: false # check ruby versions on Travis
gem 'factory_bot', '>= 4.0', require: false # for test data setup
gem 'fuubar', '>= 2.3.1', require: false # rspec formatter
gem 'rack-test', '>= 1.0.0', require: false # for testing rake servers
gem 'rspec', '>= 3.7.0', require: false # for behavioral driven testing
gem 'rubocop', '>= 0.54.0', require: false # syntax checking
gem 'ruby_audit', '>= 1.2.0', require: false # complements bundler-audit
gem 'simplecov', '>= 0.16.1', require: false # for code coverage
gem 'timecop', '>= 0.9.1', require: false # testing time dependent
gem 'travis', '>= 1.8.8', require: false # for continuous integrations
gem 'travis_check_rubies', '>= 0.2.5', require: false # check ruby versions on Travis
end

group :development do
gem 'better_errors', '~> 2.4.0', require: false
gem 'guard', '~> 2.14.2', require: false # watch for changed files
gem 'guard-rspec', '~> 4.7.3', require: false # run rspec on change
gem 'better_errors', '>= 2.4.0', require: false
gem 'guard', '>= 2.14.2', require: false # watch for changed files
gem 'guard-rspec', '>= 4.7.3', require: false # run rspec on change
gem 'wdm', '>= 0.1.0', require: false if Gem.win_platform? # supports Guard watching files on Windows OS.
end

group :doc do
gem 'sdoc', '~> 1.0.0', require: false # static documentation
gem 'sdoc', '>= 1.0.0', require: false # static documentation
end
88 changes: 44 additions & 44 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -257,51 +257,51 @@ PLATFORMS
x64-mingw32

DEPENDENCIES
activerecord (~> 5.1.5)
acts-as-taggable-array-on (~> 0.4.0)
better_errors (~> 2.4.0)
bugsnag (~> 6.6)
bundler-audit (~> 0.6.0)
coveralls (~> 0.7.1)
activerecord (>= 5.1.5)
acts-as-taggable-array-on (>= 0.4.0)
better_errors (>= 2.4.0)
bugsnag (>= 6.6)
bundler-audit (>= 0.6.0)
coveralls (>= 0.7.1)
database_cleaner (= 1.6.1)
dotenv (~> 2.2.1)
facets (~> 3.1.0)
factory_bot (~> 4.0)
fuubar (~> 2.3.1)
guard (~> 2.14.2)
guard-rspec (~> 4.7.3)
i18n (~> 0.9.5)
jsonb_accessor (~> 1.0.0)
kiba (~> 2.0.0)
mobility (~> 0.5.1)
multi_json (~> 1.13.1)
oj (~> 3.5.0)
pg (~> 1.0.0)
puma (~> 3.11.2)
rack-cache (~> 1.7.1)
rack-contrib (~> 2.0.1)
rack-heartbeat (~> 1.1.0)
rack-protection (~> 2.0.1)
rack-ssl (~> 1.4.1)
rack-test (~> 1.0.0)
rake (~> 12.3.1)
ralyxa (~> 1.7.0)
rest-client (~> 2.0.2)
route_downcaser (~> 1.2.1)
rspec (~> 3.7.0)
rubocop (~> 0.54.0)
ruby_audit (~> 1.2.0)
sdoc (~> 1.0.0)
simplecov (~> 0.16.1)
sinatra (~> 2.0.1)
sinatra-activerecord (~> 2.0.13)
sinatra-contrib (~> 2.0.1)
sinatra_logger (~> 0.1.0)
timecop (~> 0.9.1)
travis (~> 1.8.8)
travis_check_rubies (~> 0.2.5)
turnout (~> 2.4.1)
validates_email_format_of (~> 1.6.3)
dotenv (>= 2.2.1)
facets (>= 3.1.0)
factory_bot (>= 4.0)
fuubar (>= 2.3.1)
guard (>= 2.14.2)
guard-rspec (>= 4.7.3)
i18n (>= 0.9.5)
jsonb_accessor (>= 1.0.0)
kiba (>= 2.0.0)
mobility (>= 0.5.1)
multi_json (>= 1.13.1)
oj (>= 3.5.0)
pg (>= 1.0.0)
puma (>= 3.11.2)
rack-cache (>= 1.7.1)
rack-contrib (>= 2.0.1)
rack-heartbeat (>= 1.1.0)
rack-protection (>= 2.0.1)
rack-ssl (>= 1.4.1)
rack-test (>= 1.0.0)
rake (>= 12.3.1)
ralyxa (>= 1.7.0)
rest-client (>= 2.0.2)
route_downcaser (>= 1.2.1)
rspec (>= 3.7.0)
rubocop (>= 0.54.0)
ruby_audit (>= 1.2.0)
sdoc (>= 1.0.0)
simplecov (>= 0.16.1)
sinatra (>= 2.0.1)
sinatra-activerecord (>= 2.0.13)
sinatra-contrib (>= 2.0.1)
sinatra_logger (>= 0.1.0)
timecop (>= 0.9.1)
travis (>= 1.8.8)
travis_check_rubies (>= 0.2.5)
turnout (>= 2.4.1)
validates_email_format_of (>= 1.6.3)
wdm (>= 0.1.0)

BUNDLED WITH
Expand Down
2 changes: 1 addition & 1 deletion batch/rap.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rubocop && git add . && git commit -m %1 && be rake app:push
rt && rubocop && git add . && git commit -m %1 && be rake app:push
10 changes: 2 additions & 8 deletions spec/models/arm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
let!(:study) { TestFactory.test_study }
let!(:study_event) { TestFactory.test_study_event }

it 'is an instance of Arm' do
expect(subject).to be_an Arm
end

it 'is valid with valid attributes' do
expect(subject).to be_valid
end
include_examples 'valid', Arm

describe '#respond_to?' do
include_context 'shared attributes'
Expand All @@ -30,7 +24,7 @@
it { expect(subject.respond_to?(:study_events)).to be_truthy }
end

include_examples 'name'
include_examples 'attribute?', :name
include_examples 'common attributes'
end

Expand Down
8 changes: 1 addition & 7 deletions spec/models/assessment_instrument_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
let!(:instrument) { InstrumentTestFactory.test_instrument }
let!(:assess) { TestFactory.test_assessment }

it 'is an instance of AssessmentInstrument' do
expect(subject).to be_an AssessmentInstrument
end

it 'is valid with valid attributes' do
expect(subject).to be_valid
end
include_examples 'valid', AssessmentInstrument

describe '#respond_to?' do
include_context 'shared attributes'
Expand Down
10 changes: 2 additions & 8 deletions spec/models/assessment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@
let!(:assessment2) { TestFactory.test_assessment2 }
let!(:instrument) { InstrumentTestFactory.test_instrument }
let!(:assessment_from_db) { Assessment.find_or_create_by! visit: visit }

it 'is an instance of Assessment' do
expect(subject).to be_an Assessment
end

it 'is valid with valid attributes' do
expect(subject).to be_valid
end

include_examples 'valid', Assessment

describe '#respond_to?' do
include_context 'shared attributes'
Expand Down
8 changes: 1 addition & 7 deletions spec/models/choice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
subject { TestFactory.test_choice }
let!(:scale) { InstrumentTestFactory.test_response_scale }

it 'is an instance of Choice' do
expect(subject).to be_a Choice
end

it 'is valid with valid attributes' do
expect(subject).to be_valid
end
include_examples 'valid', Choice

describe '#respond_to?' do
include_context 'shared attributes'
Expand Down
15 changes: 3 additions & 12 deletions spec/models/folder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,13 @@
let!(:project1) { ProjectTestFactory.test_project }
let!(:project2) { ProjectTestFactory.test_project2 }

it 'is an instance of Folder' do
expect(subject).to be_a Folder
end

it 'is valid with valid attributes' do
expect(subject).to be_valid
end
include_examples 'valid', Folder

describe '#respond_to?' do
include_context 'shared attributes'

context '#projects' do
it { expect(attribute?(:projects)).to be_truthy }
end

include_examples 'name'
include_examples 'attribute?', :projects
include_examples 'attribute?', :name
include_examples 'common attributes'
end

Expand Down
10 changes: 2 additions & 8 deletions spec/models/hipaa_identifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
RSpec.describe HipaaIdentifier, type: :model do
subject { TestFactory.test_hipaa_identifier }

it 'is an instance of HipaaIdentifier' do
expect(subject).to be_a HipaaIdentifier
end

it 'is valid with valid attributes' do
expect(subject).to be_valid
end
include_examples 'valid', HipaaIdentifier

describe '#respond_to?' do
include_context 'shared attributes'

include_examples 'name'
include_examples 'attribute?', :name
it { expect(subject.respond_to?(:not_attribute)).not_to be_truthy }
end

Expand Down
22 changes: 8 additions & 14 deletions spec/models/instrument_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,22 @@
RSpec.describe Instrument, type: :model do
subject { Instrument.find_or_create_by! name: TestConstants::TEST_INSTRUMENT }

it 'is an instance of Instrument' do
expect(subject).to be_an Instrument
end

it 'is valid with valid attributes' do
expect(subject).to be_valid
end
include_examples 'valid', Instrument

describe '#respond_to?' do
include_context 'shared attributes'

it { expect(subject.respond_to?(:content)).to be_truthy }
it { expect(subject.respond_to?(:title)).to be_truthy }
it { expect(subject.respond_to?(:instructions)).to be_truthy }
it { expect(subject.respond_to?(:pages)).to be_truthy }
it { expect(subject.respond_to?(:assessment_instruments)).to be_truthy }
it { expect(subject.respond_to?(:assessments)).to be_truthy }
it { expect(subject.respond_to?(:study_event_instruments)).to be_truthy }
it { expect(subject.respond_to?(:study_events)).to be_truthy }
it { expect(subject.respond_to?(:items)).to be_truthy }

include_examples 'name'

include_examples 'attribute?', :instructions
include_examples 'attribute?', :content
include_examples 'attribute?', :title
include_examples 'attribute?', :pages
include_examples 'attribute?', :items
include_examples 'attribute?', :name
include_examples 'common attributes'
end

Expand Down
10 changes: 2 additions & 8 deletions spec/models/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
subject { Item.find_or_create_by! name: 'Appetite1' }
let!(:instrument) { InstrumentTestFactory.test_instrument }

it 'is an instance of Item' do
expect(subject).to be_an Item
end

it 'is valid with valid attributes' do
expect(subject).to be_valid
end
include_examples 'valid', Item

describe '#respond_to?' do
include_context 'shared attributes'
Expand All @@ -19,7 +13,7 @@
it { expect(attribute?(:instrument)).to be_truthy }
it { expect(attribute?(:response_scale)).to be_truthy }

include_examples 'name'
include_examples 'attribute?', :name
include_examples 'common attributes'
end

Expand Down
8 changes: 1 addition & 7 deletions spec/models/journal_entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
subject { TestFactory.test_journal_entry }
let!(:journal) { TestFactory.test_journal }

it 'is an instance of JournalEntry' do
expect(subject).to be_an JournalEntry
end

it 'is valid with valid attributes' do
expect(subject).to be_valid
end
include_examples 'valid', JournalEntry

describe '#respond_to?' do
include_context 'shared attributes'
Expand Down

0 comments on commit 68bca77

Please sign in to comment.