This repository has been archived by the owner on Feb 26, 2019. It is now read-only.
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 #5 from MITLibraries/workflow_element_views
Initial workflow pages
- Loading branch information
Showing
32 changed files
with
303 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
StringLiterals: | ||
EnforcedStyle: single_quotes |
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 @@ | ||
2.2.3 |
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
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,25 @@ | ||
class WorkflowsController < ApplicationController | ||
def show | ||
@workflow = Workflow.find(params[:id]) | ||
end | ||
|
||
def form_submit | ||
@workflow = Workflow.find(params[:id]) | ||
@form_errors = error_check(@workflow, params) | ||
|
||
if @form_errors.empty? | ||
flash[:success] = 'Submission was valid.' | ||
redirect_to root_path | ||
else | ||
flash[:danger] = 'There was a problem with the form submission.' | ||
render 'show' | ||
end | ||
end | ||
|
||
private | ||
|
||
def error_check(wf, params) | ||
required_fields = wf.elements.map { |e| e.display_id if e.required }.compact | ||
required_fields.map { |field| field unless params[field].present? }.compact | ||
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
Empty file.
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 @@ | ||
</fieldset> |
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,4 @@ | ||
<fieldset> | ||
<% if element.label %> | ||
<legend><%= element.label %></legend> | ||
<% end %> |
Empty file.
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 @@ | ||
</form> |
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,3 @@ | ||
<form class="form-horizontal" action="<%= workflow_submit_path(@workflow.id) %>" method="post"> | ||
<input name="authenticity_token" type="hidden" value="#{session[:_csrf_token]}" /> | ||
<span id="helpBlock" class="help-block">* indicates required field.</span> |
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 @@ | ||
<div class="form-group"> | ||
<div class="col-sm-offset-2 col-sm-10"> | ||
<button type="submit" class="btn btn-primary"><%= element.label %></button> | ||
</div> | ||
</div> |
Empty file.
Empty file.
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,16 @@ | ||
<% on_error = true if @form_errors && @form_errors.include?(element.display_id) %> | ||
|
||
<div class="form-group <%= 'has-error' if on_error %>"> | ||
<label for="<%= element.display_id %>" class="col-sm-2 control-label"><%= element.display_label %></label> | ||
<div class="col-sm-10"> | ||
<input type="text" class="form-control" id="<%= element.display_id %>" | ||
name="<%= element.display_id %>" placeholder="<%= element.label %>" | ||
value="<%= params[element.display_id] %>"> | ||
<% if element.help %> | ||
<span id="helpBlock" class="help-block"><%= element.help %></span> | ||
<% end %> | ||
<% if on_error %> | ||
<span class='help-block'><%= element.error %></span> | ||
<% end %> | ||
</div> | ||
</div> |
Empty file.
Empty file.
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,6 @@ | ||
<h1><%= @workflow.name %></h1> | ||
|
||
<% @workflow.elements.first.traverse do |element, partial| %> | ||
<%= render partial: "workflows/elements/#{element.element_type.name}#{partial}", | ||
locals: { element: element } %> | ||
<% 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 |
---|---|---|
@@ -1,7 +1,37 @@ | ||
# This file should contain all the record creation needed to seed the database with its default values. | ||
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). | ||
# | ||
# Examples: | ||
# | ||
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) | ||
# Mayor.create(name: 'Emanuel', city: cities.first) | ||
# Remove Existing ElementTypes | ||
ElementType.delete_all | ||
|
||
# Setup ElementTypes | ||
ElementType.create(id: 1, name: 'form') | ||
ElementType.create(id: 2, name: 'fieldset') | ||
ElementType.create(id: 3, name: 'text') | ||
ElementType.create(id: 4, name: 'textarea') | ||
ElementType.create(id: 5, name: 'select') | ||
ElementType.create(id: 6, name: 'option') | ||
ElementType.create(id: 7, name: 'checkbox') | ||
ElementType.create(id: 8, name: 'radio_group') | ||
ElementType.create(id: 9, name: 'radio') | ||
ElementType.create(id: 10, name: 'submit') | ||
|
||
# Remove Existing ElementTypeAccepts | ||
ElementTypeAccept.delete_all | ||
|
||
# Setup ElementTypeAccepts | ||
ElementTypeAccept.create(element_type_id: 1, accepts_element_type_id: 2) | ||
ElementTypeAccept.create(element_type_id: 1, accepts_element_type_id: 3) | ||
ElementTypeAccept.create(element_type_id: 1, accepts_element_type_id: 4) | ||
ElementTypeAccept.create(element_type_id: 1, accepts_element_type_id: 5) | ||
ElementTypeAccept.create(element_type_id: 1, accepts_element_type_id: 7) | ||
ElementTypeAccept.create(element_type_id: 1, accepts_element_type_id: 8) | ||
ElementTypeAccept.create(element_type_id: 1, accepts_element_type_id: 10) | ||
|
||
ElementTypeAccept.create(element_type_id: 2, accepts_element_type_id: 2) | ||
ElementTypeAccept.create(element_type_id: 2, accepts_element_type_id: 3) | ||
ElementTypeAccept.create(element_type_id: 2, accepts_element_type_id: 4) | ||
ElementTypeAccept.create(element_type_id: 2, accepts_element_type_id: 5) | ||
ElementTypeAccept.create(element_type_id: 2, accepts_element_type_id: 7) | ||
ElementTypeAccept.create(element_type_id: 2, accepts_element_type_id: 8) | ||
|
||
ElementTypeAccept.create(element_type_id: 5, accepts_element_type_id: 6) | ||
|
||
ElementTypeAccept.create(element_type_id: 8, accepts_element_type_id: 9) |
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,8 @@ | ||
require 'test_helper' | ||
|
||
class WorkflowsControllerTest < ActionController::TestCase | ||
test 'show' do | ||
get :show, id: workflows(:workflow_one) | ||
assert_response :success | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'test_helper' | ||
|
||
class StaticPagesTest < Capybara::Rails::TestCase | ||
def setup | ||
Rails.application.env_config['devise.mapping'] = Devise.mappings[:user] | ||
Rails.application.env_config['omniauth.auth'] = | ||
OmniAuth.config.mock_auth[:mit_oauth2] | ||
OmniAuth.config.test_mode = true | ||
end | ||
|
||
def teardown | ||
OmniAuth.config.test_mode = false | ||
OmniAuth.config.mock_auth[:mit_oauth2] = nil | ||
end | ||
|
||
test 'sign in link' do | ||
visit root_path | ||
assert page.has_link?('Sign in') | ||
refute page.has_link?('Sign out') | ||
end | ||
|
||
test 'sign out link' do | ||
OmniAuth.config.mock_auth[:mit_oauth2] = | ||
OmniAuth::AuthHash.new(provider: 'mit_oauth2', | ||
uid: '123545', | ||
info: { email: 'bob@asdf.com' }) | ||
|
||
visit '/users/auth/mit_oauth2/callback' | ||
visit root_path | ||
assert page.has_link?('Sign out') | ||
refute page.has_link?('Sign in') | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'test_helper' | ||
|
||
class WorkflowPagesTest < Capybara::Rails::TestCase | ||
def setup | ||
@workflow = workflows(:workflow_one) | ||
parent = elements(:one) | ||
fs = Element.create(workflow: @workflow, label: 'Contact Information', | ||
element_type: element_types(:fieldset), parent: parent) | ||
@input_name = Element.create(workflow: @workflow, label: 'Name', | ||
element_type: element_types(:text), | ||
parent: fs, required: true, | ||
error: 'Your name is required.') | ||
@input_email = Element.create(workflow: @workflow, label: 'Email', | ||
element_type: element_types(:text), | ||
parent: fs, required: false, | ||
help: 'Add your email if you want.') | ||
Element.create(workflow: @workflow, label: 'Submit!!!', | ||
element_type: element_types(:submit), parent: parent) | ||
end | ||
|
||
test 'can submit valid form' do | ||
visit workflow_path(@workflow) | ||
fill_in(@input_name.display_id, with: 'Example User') | ||
click_on 'Submit!!!' | ||
assert page.has_content?('Submission was valid.') | ||
end | ||
|
||
test 'invalid form submission retains values' do | ||
visit workflow_path(@workflow) | ||
fill_in(@input_email.display_id, with: 'bob@example.com') | ||
click_on 'Submit!!!' | ||
assert_equal(find_field(@input_email.display_id).value, 'bob@example.com') | ||
refute page.has_content?('Submission was valid.') | ||
end | ||
|
||
test 'invalid form submission displays errors' do | ||
visit workflow_path(@workflow) | ||
page.assert_selector('div.has-error', count: 0) | ||
fill_in(@input_email.display_id, with: 'bob@example.com') | ||
click_on 'Submit!!!' | ||
refute page.has_content?('Submission was valid.') | ||
assert page.has_content?('There was a problem with the form submission.') | ||
assert page.has_content?('Your name is required.') | ||
page.assert_selector('div.has-error', count: 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
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
Oops, something went wrong.