forked from sparc-request/sparc-request
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from bmic-development/wth-form-functionality-v…
…alidations-part-two wth - (SPARCCatalog) Form Functionality Form Builder Part II
- Loading branch information
Showing
9 changed files
with
101 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
class ItemOption < ActiveRecord::Base | ||
belongs_to :item | ||
|
||
validates :content, presence: true, if: :validate_content? | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20170213212738_add_validate_content_to_item_options.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddValidateContentToItemOptions < ActiveRecord::Migration | ||
def change | ||
add_column :item_options, :validate_content, :boolean, after: :content | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FactoryGirl.define do | ||
factory :item_option do | ||
content 'text' | ||
validate_content true | ||
item_id nil | ||
end | ||
end |
53 changes: 53 additions & 0 deletions
53
spec/features/additional_details/user_should_validation_errors_item_content_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'User should see validation errors on item content', js: true do | ||
scenario 'successfully' do | ||
service = create(:service, :with_ctrc_organization) | ||
visit new_service_additional_details_questionnaire_path(service) | ||
fill_in 'questionnaire_name', with: 'New Questionnaire' | ||
fill_in 'questionnaire_items_attributes_0_content', with: 'What is your favorite color?' | ||
select 'Radio Button', from: 'questionnaire_items_attributes_0_item_type' | ||
|
||
check 'questionnaire_items_attributes_0_required' | ||
|
||
click_button 'Create Questionnaire' | ||
|
||
expect(page).to have_content "Content can't be blank" | ||
end | ||
|
||
scenario 'successfully' do | ||
service = create(:service, :with_ctrc_organization) | ||
visit new_service_additional_details_questionnaire_path(service) | ||
fill_in 'questionnaire_name', with: 'New Questionnaire' | ||
fill_in 'questionnaire_items_attributes_0_content', with: 'What is your favorite color?' | ||
select 'Radio Button', from: 'questionnaire_items_attributes_0_item_type' | ||
fill_in 'questionnaire_items_attributes_0_item_options_attributes_0_content', with: 'Green' | ||
click_link 'Add another Option' | ||
|
||
check 'questionnaire_items_attributes_0_required' | ||
|
||
click_button 'Create Questionnaire' | ||
|
||
expect(page).to have_content "Content can't be blank" | ||
end | ||
|
||
scenario 'successfully' do | ||
service = create(:service, :with_ctrc_organization) | ||
visit new_service_additional_details_questionnaire_path(service) | ||
fill_in 'questionnaire_name', with: 'New Questionnaire' | ||
fill_in 'questionnaire_items_attributes_0_content', with: 'What is your favorite color?' | ||
select 'Radio Button', from: 'questionnaire_items_attributes_0_item_type' | ||
fill_in 'questionnaire_items_attributes_0_item_options_attributes_0_content', with: 'Green' | ||
click_link 'Add another Option' | ||
fill_in 'questionnaire_items_attributes_0_item_options_attributes_1_content', with: 'Red' | ||
|
||
check 'questionnaire_items_attributes_0_required' | ||
|
||
click_button 'Create Questionnaire' | ||
|
||
expect(page).not_to have_content "Content can't be blank" | ||
expect(current_path).to eq service_additional_details_questionnaires_path(service) | ||
expect(Questionnaire.count).to eq 1 | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters