diff --git a/app/assets/stylesheets/error_templates.css.scss b/app/assets/stylesheets/error_templates.css.scss new file mode 100644 index 00000000..bbd8b05e --- /dev/null +++ b/app/assets/stylesheets/error_templates.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the error_templates controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss new file mode 100644 index 00000000..6ec6a8ff --- /dev/null +++ b/app/assets/stylesheets/scaffolds.css.scss @@ -0,0 +1,69 @@ +body { + background-color: #fff; + color: #333; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + &:visited { + color: #666; + } + &:hover { + color: #fff; + background-color: #000; + } +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px; + padding-bottom: 0; + margin-bottom: 20px; + background-color: #f0f0f0; + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + margin-bottom: 0px; + background-color: #c00; + color: #fff; + } + ul li { + font-size: 12px; + list-style: square; + } +} diff --git a/app/controllers/error_templates_controller.rb b/app/controllers/error_templates_controller.rb new file mode 100644 index 00000000..1007eeaf --- /dev/null +++ b/app/controllers/error_templates_controller.rb @@ -0,0 +1,86 @@ +class ErrorTemplatesController < ApplicationController + before_action :set_error_template, only: [:show, :edit, :update, :destroy] + + def authorize! + authorize(@error_templates || @error_template) + end + private :authorize! + + # GET /error_templates + # GET /error_templates.json + def index + @error_templates = ErrorTemplate.all + authorize! + end + + # GET /error_templates/1 + # GET /error_templates/1.json + def show + authorize! + end + + # GET /error_templates/new + def new + @error_template = ErrorTemplate.new + authorize! + end + + # GET /error_templates/1/edit + def edit + authorize! + end + + # POST /error_templates + # POST /error_templates.json + def create + authorize! + @error_template = ErrorTemplate.new(error_template_params) + + respond_to do |format| + if @error_template.save + format.html { redirect_to @error_template, notice: 'Error template was successfully created.' } + format.json { render :show, status: :created, location: @error_template } + else + format.html { render :new } + format.json { render json: @error_template.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /error_templates/1 + # PATCH/PUT /error_templates/1.json + def update + authorize! + respond_to do |format| + if @error_template.update(error_template_params) + format.html { redirect_to @error_template, notice: 'Error template was successfully updated.' } + format.json { render :show, status: :ok, location: @error_template } + else + format.html { render :edit } + format.json { render json: @error_template.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /error_templates/1 + # DELETE /error_templates/1.json + def destroy + authorize! + @error_template.destroy + respond_to do |format| + format.html { redirect_to error_templates_url, notice: 'Error template was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_error_template + @error_template = ErrorTemplate.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def error_template_params + params.fetch(:error_template, {}) + end +end diff --git a/app/helpers/error_templates_helper.rb b/app/helpers/error_templates_helper.rb new file mode 100644 index 00000000..f42cf302 --- /dev/null +++ b/app/helpers/error_templates_helper.rb @@ -0,0 +1,2 @@ +module ErrorTemplatesHelper +end diff --git a/app/policies/error_template_policy.rb b/app/policies/error_template_policy.rb new file mode 100644 index 00000000..30bdbd24 --- /dev/null +++ b/app/policies/error_template_policy.rb @@ -0,0 +1,3 @@ +class ErrorTemplatePolicy < AdminOnlyPolicy + +end diff --git a/app/views/error_templates/_form.html.erb b/app/views/error_templates/_form.html.erb new file mode 100644 index 00000000..17371914 --- /dev/null +++ b/app/views/error_templates/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_for(@error_template) do |f| %> + <% if @error_template.errors.any? %> +
+

<%= pluralize(@error_template.errors.count, "error") %> prohibited this error_template from being saved:

+ + +
+ <% end %> + +
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/error_templates/edit.html.erb b/app/views/error_templates/edit.html.erb new file mode 100644 index 00000000..0d2919e5 --- /dev/null +++ b/app/views/error_templates/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Error Template

+ +<%= render 'form' %> + +<%= link_to 'Show', @error_template %> | +<%= link_to 'Back', error_templates_path %> diff --git a/app/views/error_templates/index.html.erb b/app/views/error_templates/index.html.erb new file mode 100644 index 00000000..65829aeb --- /dev/null +++ b/app/views/error_templates/index.html.erb @@ -0,0 +1,25 @@ +

<%= notice %>

+ +

Listing Error Templates

+ + + + + + + + + + <% @error_templates.each do |error_template| %> + + + + + + <% end %> + +
<%= link_to 'Show', error_template %><%= link_to 'Edit', edit_error_template_path(error_template) %><%= link_to 'Destroy', error_template, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Error template', new_error_template_path %> diff --git a/app/views/error_templates/index.json.jbuilder b/app/views/error_templates/index.json.jbuilder new file mode 100644 index 00000000..ce85b2be --- /dev/null +++ b/app/views/error_templates/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@error_templates) do |error_template| + json.extract! error_template, :id + json.url error_template_url(error_template, format: :json) +end diff --git a/app/views/error_templates/new.html.erb b/app/views/error_templates/new.html.erb new file mode 100644 index 00000000..6b4acd06 --- /dev/null +++ b/app/views/error_templates/new.html.erb @@ -0,0 +1,5 @@ +

New Error Template

+ +<%= render 'form' %> + +<%= link_to 'Back', error_templates_path %> diff --git a/app/views/error_templates/show.html.erb b/app/views/error_templates/show.html.erb new file mode 100644 index 00000000..9debad9b --- /dev/null +++ b/app/views/error_templates/show.html.erb @@ -0,0 +1,4 @@ +

<%= notice %>

+ +<%= link_to 'Edit', edit_error_template_path(@error_template) %> | +<%= link_to 'Back', error_templates_path %> diff --git a/app/views/error_templates/show.json.jbuilder b/app/views/error_templates/show.json.jbuilder new file mode 100644 index 00000000..1cbaff55 --- /dev/null +++ b/app/views/error_templates/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @error_template, :id, :created_at, :updated_at diff --git a/config/routes.rb b/config/routes.rb index d340a204..ce5be3ae 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,7 @@ FILENAME_REGEXP = /[\w\.]+/ unless Kernel.const_defined?(:FILENAME_REGEXP) Rails.application.routes.draw do + resources :error_templates resources :file_templates do collection do get 'by_file_type/:file_type_id', as: :by_file_type, action: :by_file_type diff --git a/test/controllers/error_templates_controller_test.rb b/test/controllers/error_templates_controller_test.rb new file mode 100644 index 00000000..452ad134 --- /dev/null +++ b/test/controllers/error_templates_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class ErrorTemplatesControllerTest < ActionController::TestCase + setup do + @error_template = error_templates(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:error_templates) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create error_template" do + assert_difference('ErrorTemplate.count') do + post :create, error_template: { } + end + + assert_redirected_to error_template_path(assigns(:error_template)) + end + + test "should show error_template" do + get :show, id: @error_template + assert_response :success + end + + test "should get edit" do + get :edit, id: @error_template + assert_response :success + end + + test "should update error_template" do + patch :update, id: @error_template, error_template: { } + assert_redirected_to error_template_path(assigns(:error_template)) + end + + test "should destroy error_template" do + assert_difference('ErrorTemplate.count', -1) do + delete :destroy, id: @error_template + end + + assert_redirected_to error_templates_path + end +end