Skip to content

Commit

Permalink
Add required to template creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey Terrell committed Aug 14, 2015
1 parent 3706742 commit a37a6b6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/form_templates_controller.rb
Expand Up @@ -60,7 +60,7 @@ def find_template
end

def form_template_params
params.require(:form_template).permit(:title, {:properties_attributes => [:id, :name, :visible]})
params.require(:form_template).permit(:title, {:properties_attributes => [:id, :name, :visible, :required]})
end

def template_class
Expand Down
3 changes: 2 additions & 1 deletion app/views/admin/form_templates/_form.html.erb
Expand Up @@ -10,7 +10,8 @@
</div>
</div>
<div class="panel-body">
<%= p.input :visible, :label => "Show", :wrapper => :inline %>
<%= p.input :visible, :label => "Show" %>
<%= p.input :required %>
<%= p.input :name, :as => :hidden %>
</div>
</div>
Expand Down
@@ -0,0 +1,5 @@
class AddRequiredToFormTemplateProperties < ActiveRecord::Migration
def change
add_column :form_template_properties, :required, :boolean
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150803175310) do
ActiveRecord::Schema.define(version: 20150814174059) do

create_table "bookmarks", force: :cascade do |t|
t.integer "user_id", null: false
Expand All @@ -38,6 +38,7 @@
t.integer "form_template_id"
t.string "name", null: false
t.boolean "visible", default: false
t.boolean "required"
end

create_table "form_templates", force: :cascade do |t|
Expand Down
12 changes: 11 additions & 1 deletion spec/features/template_management_spec.rb
Expand Up @@ -30,6 +30,7 @@
before do
fill_in "form_template_title", :with => template_name
check_fields.each {|field| show_field field}
require_field :title
click_button "Save Template"
end

Expand All @@ -53,6 +54,9 @@
(GenericAssetForm.terms - check_fields).each do |t|
expect(checkboxes[t]).not_to be_checked
end
within "#title .form_template_properties_required" do
expect(find("input[type=checkbox]")).to be_checked
end
end

context "when submitting changes" do
Expand Down Expand Up @@ -102,7 +106,7 @@ def navigate_to_template_admin_path
def checkbox_states
checkboxes = HashWithIndifferentAccess.new
all('.template-property').each do |el|
checkboxes[el.find(".panel-title").text] = el.find("input[type=checkbox]")
checkboxes[el.find(".panel-title").text] = el.find(".form_template_properties_visible input[type=checkbox]")
end

checkboxes
Expand All @@ -120,3 +124,9 @@ def hide_field(field)
end
end

def require_field(field)
within "##{field}" do
check "Required"
end
end

0 comments on commit a37a6b6

Please sign in to comment.