From 14802473f7019c71acd479271ab0a59fee40595b Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Tue, 19 Apr 2016 11:52:02 +0200 Subject: [PATCH] lazy me generates a whole scaffold for hosts --- app/assets/javascripts/lxd_hosts.coffee | 3 + app/assets/stylesheets/lxd_hosts.scss | 3 + app/controllers/lxd_hosts_controller.rb | 74 +++++++++++++++++++ app/helpers/lxd_hosts_helper.rb | 2 + app/views/lxd_hosts/_form.html.erb | 33 +++++++++ app/views/lxd_hosts/edit.html.erb | 6 ++ app/views/lxd_hosts/index.html.erb | 29 ++++++++ app/views/lxd_hosts/index.json.jbuilder | 4 + app/views/lxd_hosts/new.html.erb | 5 ++ app/views/lxd_hosts/show.html.erb | 14 ++++ app/views/lxd_hosts/show.json.jbuilder | 1 + config/routes.rb | 1 + test/controllers/lxd_hosts_controller_test.rb | 49 ++++++++++++ 13 files changed, 224 insertions(+) create mode 100644 app/assets/javascripts/lxd_hosts.coffee create mode 100644 app/assets/stylesheets/lxd_hosts.scss create mode 100644 app/controllers/lxd_hosts_controller.rb create mode 100644 app/helpers/lxd_hosts_helper.rb create mode 100644 app/views/lxd_hosts/_form.html.erb create mode 100644 app/views/lxd_hosts/edit.html.erb create mode 100644 app/views/lxd_hosts/index.html.erb create mode 100644 app/views/lxd_hosts/index.json.jbuilder create mode 100644 app/views/lxd_hosts/new.html.erb create mode 100644 app/views/lxd_hosts/show.html.erb create mode 100644 app/views/lxd_hosts/show.json.jbuilder create mode 100644 test/controllers/lxd_hosts_controller_test.rb diff --git a/app/assets/javascripts/lxd_hosts.coffee b/app/assets/javascripts/lxd_hosts.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/lxd_hosts.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/lxd_hosts.scss b/app/assets/stylesheets/lxd_hosts.scss new file mode 100644 index 0000000..4752d3d --- /dev/null +++ b/app/assets/stylesheets/lxd_hosts.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the lxd_hosts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/lxd_hosts_controller.rb b/app/controllers/lxd_hosts_controller.rb new file mode 100644 index 0000000..eed8dfa --- /dev/null +++ b/app/controllers/lxd_hosts_controller.rb @@ -0,0 +1,74 @@ +class LxdHostsController < ApplicationController + before_action :set_lxd_host, only: [:show, :edit, :update, :destroy] + + # GET /lxd_hosts + # GET /lxd_hosts.json + def index + @lxd_hosts = LxdHost.all + end + + # GET /lxd_hosts/1 + # GET /lxd_hosts/1.json + def show + end + + # GET /lxd_hosts/new + def new + @lxd_host = LxdHost.new + end + + # GET /lxd_hosts/1/edit + def edit + end + + # POST /lxd_hosts + # POST /lxd_hosts.json + def create + @lxd_host = LxdHost.new(lxd_host_params) + + respond_to do |format| + if @lxd_host.save + format.html { redirect_to @lxd_host, notice: 'Lxd host was successfully created.' } + format.json { render :show, status: :created, location: @lxd_host } + else + format.html { render :new } + format.json { render json: @lxd_host.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /lxd_hosts/1 + # PATCH/PUT /lxd_hosts/1.json + def update + respond_to do |format| + if @lxd_host.update(lxd_host_params) + format.html { redirect_to @lxd_host, notice: 'Lxd host was successfully updated.' } + format.json { render :show, status: :ok, location: @lxd_host } + else + format.html { render :edit } + format.json { render json: @lxd_host.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /lxd_hosts/1 + # DELETE /lxd_hosts/1.json + def destroy + @lxd_host.destroy + respond_to do |format| + format.html { redirect_to lxd_hosts_url, notice: 'Lxd host was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_lxd_host + @lxd_host = LxdHost.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def lxd_host_params + params.require(:lxd_host).permit(:name, :uri, :password, :password_confirmation) + end +end diff --git a/app/helpers/lxd_hosts_helper.rb b/app/helpers/lxd_hosts_helper.rb new file mode 100644 index 0000000..b77befd --- /dev/null +++ b/app/helpers/lxd_hosts_helper.rb @@ -0,0 +1,2 @@ +module LxdHostsHelper +end diff --git a/app/views/lxd_hosts/_form.html.erb b/app/views/lxd_hosts/_form.html.erb new file mode 100644 index 0000000..b19cc8f --- /dev/null +++ b/app/views/lxd_hosts/_form.html.erb @@ -0,0 +1,33 @@ +<%= form_for(@lxd_host) do |f| %> + <% if @lxd_host.errors.any? %> +
+

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

+ + +
+ <% end %> + +
+ <%= f.label :name %>
+ <%= f.text_area :name %> +
+
+ <%= f.label :uri %>
+ <%= f.text_area :uri %> +
+
+ <%= f.label :password %>
+ <%= f.password_field :password %> +
+
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/lxd_hosts/edit.html.erb b/app/views/lxd_hosts/edit.html.erb new file mode 100644 index 0000000..83c0643 --- /dev/null +++ b/app/views/lxd_hosts/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Lxd Host

+ +<%= render 'form' %> + +<%= link_to 'Show', @lxd_host %> | +<%= link_to 'Back', lxd_hosts_path %> diff --git a/app/views/lxd_hosts/index.html.erb b/app/views/lxd_hosts/index.html.erb new file mode 100644 index 0000000..e281d81 --- /dev/null +++ b/app/views/lxd_hosts/index.html.erb @@ -0,0 +1,29 @@ +

<%= notice %>

+ +

Listing Lxd Hosts

+ + + + + + + + + + + + <% @lxd_hosts.each do |lxd_host| %> + + + + + + + + <% end %> + +
NameUri
<%= lxd_host.name %><%= lxd_host.uri %><%= link_to 'Show', lxd_host %><%= link_to 'Edit', edit_lxd_host_path(lxd_host) %><%= link_to 'Destroy', lxd_host, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Lxd host', new_lxd_host_path %> diff --git a/app/views/lxd_hosts/index.json.jbuilder b/app/views/lxd_hosts/index.json.jbuilder new file mode 100644 index 0000000..c00060f --- /dev/null +++ b/app/views/lxd_hosts/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@lxd_hosts) do |lxd_host| + json.extract! lxd_host, :id, :name, :uri + json.url lxd_host_url(lxd_host, format: :json) +end diff --git a/app/views/lxd_hosts/new.html.erb b/app/views/lxd_hosts/new.html.erb new file mode 100644 index 0000000..56a4896 --- /dev/null +++ b/app/views/lxd_hosts/new.html.erb @@ -0,0 +1,5 @@ +

New Lxd Host

+ +<%= render 'form' %> + +<%= link_to 'Back', lxd_hosts_path %> diff --git a/app/views/lxd_hosts/show.html.erb b/app/views/lxd_hosts/show.html.erb new file mode 100644 index 0000000..98dbe18 --- /dev/null +++ b/app/views/lxd_hosts/show.html.erb @@ -0,0 +1,14 @@ +

<%= notice %>

+ +

+ Name: + <%= @lxd_host.name %> +

+ +

+ Uri: + <%= @lxd_host.uri %> +

+ +<%= link_to 'Edit', edit_lxd_host_path(@lxd_host) %> | +<%= link_to 'Back', lxd_hosts_path %> diff --git a/app/views/lxd_hosts/show.json.jbuilder b/app/views/lxd_hosts/show.json.jbuilder new file mode 100644 index 0000000..7f7df55 --- /dev/null +++ b/app/views/lxd_hosts/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @lxd_host, :id, :name, :uri, :created_at, :updated_at diff --git a/config/routes.rb b/config/routes.rb index 5ba9fb0..4312c64 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :lxd_hosts resources :certificates get 'dashboard/index' diff --git a/test/controllers/lxd_hosts_controller_test.rb b/test/controllers/lxd_hosts_controller_test.rb new file mode 100644 index 0000000..2055c29 --- /dev/null +++ b/test/controllers/lxd_hosts_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class LxdHostsControllerTest < ActionController::TestCase + setup do + @lxd_host = lxd_hosts(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:lxd_hosts) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create lxd_host" do + assert_difference('LxdHost.count') do + post :create, lxd_host: { name: @lxd_host.name, password: 'secret', password_confirmation: 'secret', uri: @lxd_host.uri } + end + + assert_redirected_to lxd_host_path(assigns(:lxd_host)) + end + + test "should show lxd_host" do + get :show, id: @lxd_host + assert_response :success + end + + test "should get edit" do + get :edit, id: @lxd_host + assert_response :success + end + + test "should update lxd_host" do + patch :update, id: @lxd_host, lxd_host: { name: @lxd_host.name, password: 'secret', password_confirmation: 'secret', uri: @lxd_host.uri } + assert_redirected_to lxd_host_path(assigns(:lxd_host)) + end + + test "should destroy lxd_host" do + assert_difference('LxdHost.count', -1) do + delete :destroy, id: @lxd_host + end + + assert_redirected_to lxd_hosts_path + end +end