diff --git a/app/assets/javascripts/certificates.coffee b/app/assets/javascripts/certificates.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/certificates.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/certificates.scss b/app/assets/stylesheets/certificates.scss new file mode 100644 index 0000000..6019482 --- /dev/null +++ b/app/assets/stylesheets/certificates.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the certificates 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.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 0000000..ed7a765 --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,73 @@ +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/certificates_controller.rb b/app/controllers/certificates_controller.rb new file mode 100644 index 0000000..d31535f --- /dev/null +++ b/app/controllers/certificates_controller.rb @@ -0,0 +1,74 @@ +class CertificatesController < ApplicationController + before_action :set_certificate, only: [:show, :edit, :update, :destroy] + + # GET /certificates + # GET /certificates.json + def index + @certificates = Certificate.all + end + + # GET /certificates/1 + # GET /certificates/1.json + def show + end + + # GET /certificates/new + def new + @certificate = Certificate.new + end + + # GET /certificates/1/edit + def edit + end + + # POST /certificates + # POST /certificates.json + def create + @certificate = Certificate.new(certificate_params) + + respond_to do |format| + if @certificate.save + format.html { redirect_to @certificate, notice: 'Certificate was successfully created.' } + format.json { render :show, status: :created, location: @certificate } + else + format.html { render :new } + format.json { render json: @certificate.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /certificates/1 + # PATCH/PUT /certificates/1.json + def update + respond_to do |format| + if @certificate.update(certificate_params) + format.html { redirect_to @certificate, notice: 'Certificate was successfully updated.' } + format.json { render :show, status: :ok, location: @certificate } + else + format.html { render :edit } + format.json { render json: @certificate.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /certificates/1 + # DELETE /certificates/1.json + def destroy + @certificate.destroy + respond_to do |format| + format.html { redirect_to certificates_url, notice: 'Certificate was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_certificate + @certificate = Certificate.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def certificate_params + params.require(:certificate).permit(:key, :cert, :active) + end +end diff --git a/app/helpers/certificates_helper.rb b/app/helpers/certificates_helper.rb new file mode 100644 index 0000000..1bc2041 --- /dev/null +++ b/app/helpers/certificates_helper.rb @@ -0,0 +1,2 @@ +module CertificatesHelper +end diff --git a/app/views/certificates/_form.html.erb b/app/views/certificates/_form.html.erb new file mode 100644 index 0000000..10b22d8 --- /dev/null +++ b/app/views/certificates/_form.html.erb @@ -0,0 +1,29 @@ +<%= form_for(@certificate) do |f| %> + <% if @certificate.errors.any? %> +
+

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

+ + +
+ <% end %> + +
+ <%= f.label :key %>
+ <%= f.text_area :key %> +
+
+ <%= f.label :cert %>
+ <%= f.text_area :cert %> +
+
+ <%= f.label :active %>
+ <%= f.check_box :active %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/certificates/edit.html.erb b/app/views/certificates/edit.html.erb new file mode 100644 index 0000000..09bf928 --- /dev/null +++ b/app/views/certificates/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Certificate

+ +<%= render 'form' %> + +<%= link_to 'Show', @certificate %> | +<%= link_to 'Back', certificates_path %> diff --git a/app/views/certificates/index.html.erb b/app/views/certificates/index.html.erb new file mode 100644 index 0000000..af96ffb --- /dev/null +++ b/app/views/certificates/index.html.erb @@ -0,0 +1,31 @@ +

<%= notice %>

+ +

Listing Certificates

+ + + + + + + + + + + + + <% @certificates.each do |certificate| %> + + + + + + + + + <% end %> + +
KeyCertActive
<%= certificate.key %><%= certificate.cert %><%= certificate.active %><%= link_to 'Show', certificate %><%= link_to 'Edit', edit_certificate_path(certificate) %><%= link_to 'Destroy', certificate, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Certificate', new_certificate_path %> diff --git a/app/views/certificates/index.json.jbuilder b/app/views/certificates/index.json.jbuilder new file mode 100644 index 0000000..59de5a6 --- /dev/null +++ b/app/views/certificates/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@certificates) do |certificate| + json.extract! certificate, :id, :key, :cert, :active + json.url certificate_url(certificate, format: :json) +end diff --git a/app/views/certificates/new.html.erb b/app/views/certificates/new.html.erb new file mode 100644 index 0000000..d125662 --- /dev/null +++ b/app/views/certificates/new.html.erb @@ -0,0 +1,5 @@ +

New Certificate

+ +<%= render 'form' %> + +<%= link_to 'Back', certificates_path %> diff --git a/app/views/certificates/show.html.erb b/app/views/certificates/show.html.erb new file mode 100644 index 0000000..4750646 --- /dev/null +++ b/app/views/certificates/show.html.erb @@ -0,0 +1,19 @@ +

<%= notice %>

+ +

+ Key: + <%= @certificate.key %> +

+ +

+ Cert: + <%= @certificate.cert %> +

+ +

+ Active: + <%= @certificate.active %> +

+ +<%= link_to 'Edit', edit_certificate_path(@certificate) %> | +<%= link_to 'Back', certificates_path %> diff --git a/app/views/certificates/show.json.jbuilder b/app/views/certificates/show.json.jbuilder new file mode 100644 index 0000000..bcae0cf --- /dev/null +++ b/app/views/certificates/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @certificate, :id, :key, :cert, :active, :created_at, :updated_at diff --git a/config/routes.rb b/config/routes.rb index 9f05377..5ba9fb0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :certificates get 'dashboard/index' # The priority is based upon order of creation: first created -> highest priority. diff --git a/test/controllers/certificates_controller_test.rb b/test/controllers/certificates_controller_test.rb new file mode 100644 index 0000000..172065e --- /dev/null +++ b/test/controllers/certificates_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class CertificatesControllerTest < ActionController::TestCase + setup do + @certificate = certificates(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:certificates) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create certificate" do + assert_difference('Certificate.count') do + post :create, certificate: { active: @certificate.active, cert: @certificate.cert, key: @certificate.key } + end + + assert_redirected_to certificate_path(assigns(:certificate)) + end + + test "should show certificate" do + get :show, id: @certificate + assert_response :success + end + + test "should get edit" do + get :edit, id: @certificate + assert_response :success + end + + test "should update certificate" do + patch :update, id: @certificate, certificate: { active: @certificate.active, cert: @certificate.cert, key: @certificate.key } + assert_redirected_to certificate_path(assigns(:certificate)) + end + + test "should destroy certificate" do + assert_difference('Certificate.count', -1) do + delete :destroy, id: @certificate + end + + assert_redirected_to certificates_path + end +end