Skip to content

Commit

Permalink
refactor shared spec code into shared module
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbeales committed Mar 27, 2018
1 parent 0d6185a commit 4ed2656
Show file tree
Hide file tree
Showing 26 changed files with 153 additions and 271 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

[![Coverage Status](https://coveralls.io/repos/stevenbeales/mental-test/badge.svg?branch=master)](https://coveralls.io/r/stevenbeales/mental-test?branch=master)

[![Dependency Status](https://beta.gemnasium.com/badges/github.com/stevenbeales/mental-test.svg)](https://beta.gemnasium.com/projects/github.com/stevenbeales/mental-test)
[![Dependency Status](https://beta.gemnasium.com/badges/github.com/stevenbeales/mental-test.svg)](https://beta.gemnasium.com/projects/github.com/stevenbeales/mental-test)

<img title="Scrutinizer Code Quality" src="https://scrutinizer-ci.com/g/stevenbeales/mental-test/badges/quality-score.png?b=master">
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/stevenbeales/mental-test/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/stevenbeales/mental-test/?branch=master)

<a href="https://codeclimate.com/github/stevenbeales/mental-test/maintainability"><img src="https://api.codeclimate.com/v1/badges/6574b93819edbc0cff7d/maintainability" /></a>
[![Maintainability](https://api.codeclimate.com/v1/badges/6574b93819edbc0cff7d/maintainability)](https://codeclimate.com/github/stevenbeales/mental-test/maintainability)

[![Inline docs](http://inch-ci.org/github/stevenbeales/mental-test.svg?branch=master)](http://inch-ci.org/github/stevenbeales/mental-test)

Expand All @@ -17,14 +17,14 @@
An Alexa skill for validated Mental Health Self-Assessments, written in Ruby using the Sinatra and Ralyxa frameworks.

The application supports importing Surveys and Instruments from SurveyJS.io and REDCap.
<p>TODO - The application supports automated scoring of Instruments where applicable.</p>
<p>TODO - The application will direct you to a physician or clinical trial that specializes in your assessed conditions.</p>
TODO - The application supports automated scoring of Instruments where applicable.
TODO - The application will direct you to a physician or clinical trial that specializes in your assessed conditions.

Disclaimer. These statements have not been validated by the FDA. This skill is not intended to diagnose or treat any condition.

To install dependencies -

1) Install Postgres 9.4 or higher. This skill uses Postgres jsonb columns to store indexed unstructured data.
1) Install Postgres 9.4 or higher. This skill uses Postgres jsonb columns to store indexed unstructured data.
2) Use bundler - bundle install - to install all other gems from the Gemfile.
3) bundle exec rake db:setup - To generate test and development databases and seed the databases with test data
4) Supports Travis Continuous Integration if you have linked Travis CI and Github accounts.
Expand All @@ -37,7 +37,7 @@ TO run the test suite -

To generate the skill documentation -

1) rake rdoc
1) rake rdoc

## Contributing

Expand Down
3 changes: 0 additions & 3 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,17 @@
name TestConstants::TEST_VISIT
association :user, factory: :test_user
association :survey, factory: :test_survey

initialize_with do
survey = FactoryInitializer.test_survey
user = FactoryInitializer.test_user
Visit.find_or_create_by!(name: TestConstants::TEST_VISIT, survey: survey, user: user)
end
end


factory :test_visit2, class: 'Visit' do
name TestConstants::TEST_VISIT
association :user, factory: :timmy
association :survey, factory: :test_survey

initialize_with do
survey = FactoryInitializer.test_survey
user2 = FactoryInitializer.test_user2
Expand Down
11 changes: 3 additions & 8 deletions spec/models/arm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
end

describe '#respond_to?' do
include_context 'shared attributes'
context '#name' do
it { expect(subject.respond_to?(:name)).to be_truthy }
end
Expand All @@ -30,15 +31,9 @@
context '#study_events' do
it { expect(subject.respond_to?(:study_events)).to be_truthy }
end
context '#created_at' do
it { expect(subject.respond_to?(:created_at)).to be_truthy }
end
context '#updated_at' do
it { expect(subject.respond_to?(:updated_at)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end
context '#not_an_attibute' do
it { expect(subject.respond_to?(:not_an_attibute)).not_to be_truthy }
end
end

describe '#name' do
Expand Down
17 changes: 6 additions & 11 deletions spec/models/assessment_instrument_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe AssessmentInstrument, type: :model do
subject { TestFactory.test_assessment_instrument }
let!(:instrument) { Instrument.find_by name: TestConstants::TEST_INSTRUMENT }
let!(:instrument) { InstrumentTestFactory.test_instrument }
let!(:assess) { TestFactory.test_assessment }

it 'is an instance of AssessmentInstrument' do
Expand All @@ -14,21 +14,16 @@
end

describe '#respond_to?' do
include_context 'shared attributes'
context '#assessment' do
it { expect(subject.respond_to?(:assessment)).to be_truthy }
it { expect(attribute?(:assessment)).to be_truthy }
end
context '#instrument' do
it { expect(subject.respond_to?(:instrument)).to be_truthy }
it { expect(attribute?(:instrument)).to be_truthy }
end
context '#created_at' do
it { expect(subject.respond_to?(:created_at)).to be_truthy }
end
context '#updated_at' do
it { expect(subject.respond_to?(:updated_at)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end
context '#not_an_attibute' do
it { expect(subject.respond_to?(:not_an_attibute)).not_to be_truthy }
end
end

describe '#instrument' do
Expand Down
13 changes: 4 additions & 9 deletions spec/models/assessment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let!(:user) { TestFactory.test_user }
let!(:visit) { TestFactory.test_visit }
let!(:assessment2) { TestFactory.test_assessment2 }
let!(:instrument) { TestFactory.test_instrument }
let!(:instrument) { InstrumentTestFactory.test_instrument }
let!(:assessment_from_db) { Assessment.find_or_create_by! visit: visit }

it 'is an instance of Assessment' do
Expand All @@ -18,6 +18,7 @@
end

describe '#respond_to?' do
include_context 'shared attributes'
context '#visit' do
it { expect(subject.respond_to?(:visit)).to be_truthy }
end
Expand All @@ -42,15 +43,9 @@
context '#scores' do
it { expect(subject.respond_to?(:scores)).to be_truthy }
end
context '#created_at' do
it { expect(subject.respond_to?(:created_at)).to be_truthy }
end
context '#updated_at' do
it { expect(subject.respond_to?(:updated_at)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end
context '#not_an_attibute' do
it { expect(subject.respond_to?(:not_an_attibute)).not_to be_truthy }
end
end

describe '#visit' do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/choice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe Choice, type: :model do
subject { TestFactory.test_choice }
let!(:scale) { TestFactory.test_response_scale }
let!(:scale) { InstrumentTestFactory.test_response_scale }

it 'is an instance of Choice' do
expect(subject).to be_a Choice
Expand Down
17 changes: 6 additions & 11 deletions spec/models/folder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

RSpec.describe Folder, type: :model do
subject { TestFactory.test_folder }
let!(:project1) { TestFactory.test_project }
let!(:project2) { TestFactory.test_project2 }
subject { ProjectTestFactory.test_folder }
let!(:project1) { ProjectTestFactory.test_project }
let!(:project2) { ProjectTestFactory.test_project2 }

it 'is an instance of Folder' do
expect(subject).to be_a Folder
Expand All @@ -14,19 +14,14 @@
end

describe '#respond_to?' do
include_context 'shared attributes'
context '#name' do
it { expect(subject.respond_to?(:name)).to be_truthy }
end
it { expect(subject.respond_to?(:projects)).to be_truthy }
context '#created_at' do
it { expect(subject.respond_to?(:created_at)).to be_truthy }
end
context '#updated_at' do
it { expect(subject.respond_to?(:updated_at)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end
context '#not_an_attibute' do
it { expect(subject.respond_to?(:not_an_attibute)).not_to be_truthy }
end
end

describe '#name' do
Expand Down
12 changes: 4 additions & 8 deletions spec/models/item_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# frozen_string_literal: true

RSpec.describe Item, type: :model do
subject { described_class.find_or_create_by! name: 'Appetite1' }
let!(:instrument) do
Instrument.find_or_create_by! name: TestConstants::TEST_INSTRUMENT
end
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
Expand Down Expand Up @@ -33,9 +31,7 @@
end

describe '#name' do
after(:each) do
subject.restore_attributes
end
include_context 'restore attributes'

it 'is required' do
subject.name = nil
Expand Down Expand Up @@ -72,7 +68,7 @@

describe '#instrument' do
it do
expect(subject.instrument).to eq(instrument)
expect(subject.instrument.id).to eq(instrument.id)
end
end

Expand Down
11 changes: 3 additions & 8 deletions spec/models/journal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,15 @@
end

describe '#respond_to?' do
include_context 'shared attributes'
context '#name' do
it { expect(subject.respond_to?(:name)).to be_truthy }
end
it { expect(subject.respond_to?(:participant)).to be_truthy }
it { expect(subject.respond_to?(:journal_entries)).to be_truthy }
context '#created_at' do
it { expect(subject.respond_to?(:created_at)).to be_truthy }
end
context '#updated_at' do
it { expect(subject.respond_to?(:updated_at)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end
context '#not_an_attibute' do
it { expect(subject.respond_to?(:not_an_attibute)).not_to be_truthy }
end
end

describe '#list_entries' do
Expand Down
12 changes: 4 additions & 8 deletions spec/models/project_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

RSpec.describe Project, type: :model do
subject { TestFactory.test_project }
let!(:folder1) { TestFactory.test_folder }
subject { ProjectTestFactory.test_project }
let!(:folder1) { ProjectTestFactory.test_folder }

it 'is an instance of Project' do
expect(subject).to be_an Project
Expand Down Expand Up @@ -31,9 +31,7 @@
end

describe '#name' do
after(:each) do
subject.restore_attributes
end
include_context 'restore attributes'

it 'is required' do
subject.name = nil
Expand All @@ -43,9 +41,7 @@
end

describe '#title' do
after(:each) do
subject.restore_attributes
end
include_context 'restore attributes'

it 'is required' do
subject.title = nil
Expand Down
2 changes: 1 addition & 1 deletion spec/models/response_scale_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

RSpec.describe ResponseScale, type: :model do
subject { TestFactory.test_response_scale }
subject { InstrumentTestFactory.test_response_scale }

it 'is an instance of ResponseScale' do
expect(subject).to be_an ResponseScale
Expand Down
10 changes: 3 additions & 7 deletions spec/models/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let!(:ur) { TestFactory.test_user }
let!(:vt) { TestFactory.test_visit }
let!(:choice) { TestFactory.test_choice }
let!(:scale) { TestFactory.test_response_scale }
let!(:scale) { InstrumentTestFactory.test_response_scale }

it 'is an instance of Response' do
expect(subject).to be_an Response
Expand All @@ -33,9 +33,7 @@
end

describe '#assessment' do
after(:each) do
subject.restore_attributes
end
include_context 'restore attributes'

it 'is required' do
subject.assessment = nil
Expand All @@ -45,9 +43,7 @@
end

describe '#value' do
after(:each) do
subject.restore_attributes
end
include_context 'restore attributes'

it 'is required' do
subject.value = nil
Expand Down
19 changes: 5 additions & 14 deletions spec/models/schedule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,19 @@
end

describe '#respond_to?' do
include_context 'shared attributes'
context '#name' do
it { expect(subject.respond_to?(:name)).to be_truthy }
end
it { expect(subject.respond_to?(:study)).to be_truthy }
it { expect(subject.respond_to?(:arms)).to be_truthy }
context '#created_at' do
it { expect(subject.respond_to?(:created_at)).to be_truthy }
end
context '#updated_at' do
it { expect(subject.respond_to?(:updated_at)).to be_truthy }
context 'common attributes' do
it { expect(timestamps?).to be_truthy }
end
context '#not_an_attibute' do
it { expect(subject.respond_to?(:not_an_attibute)).not_to be_truthy }
end
end

describe '#name' do
after(:each) do
subject.restore_attributes
end
include_context 'restore attributes'

it 'is required' do
subject.name = nil
Expand All @@ -42,9 +35,7 @@
end

describe '#study' do
after(:each) do
subject.restore_attributes
end
include_context 'restore attributes'

it do
subject.study = nil
Expand Down

0 comments on commit 4ed2656

Please sign in to comment.