From f28150b9f5c6939a50cc0e1023988f3ca2f156c3 Mon Sep 17 00:00:00 2001 From: stef Date: Wed, 17 Apr 2024 15:23:21 +0200 Subject: [PATCH] mutliple modif --- src/autogen/Gemfile | 2 + src/autogen/Gemfile.lock | 2 + .../app/controllers/anshosts_controller.rb | 70 +++++++++++++++++++ .../app/controllers/hosts_controller.rb | 2 +- .../app/controllers/test_controller.rb | 24 +++++++ src/autogen/app/data/test.json | 1 + src/autogen/app/data/test.yml | 10 +++ src/autogen/app/helpers/anshosts_helper.rb | 2 + src/autogen/app/lib/filejson.rb | 16 +++++ src/autogen/app/lib/fileyaml.rb | 13 ++++ src/autogen/app/models/anshost.rb | 6 ++ src/autogen/app/models/host.rb | 1 + .../app/views/anshosts/_anshost.html.erb | 12 ++++ .../app/views/anshosts/_anshost.json.jbuilder | 2 + src/autogen/app/views/anshosts/_form.html.erb | 28 ++++++++ src/autogen/app/views/anshosts/edit.html.erb | 10 +++ src/autogen/app/views/anshosts/index.html.erb | 14 ++++ .../app/views/anshosts/index.json.jbuilder | 1 + src/autogen/app/views/anshosts/new.html.erb | 9 +++ src/autogen/app/views/anshosts/show.html.erb | 10 +++ .../app/views/anshosts/show.json.jbuilder | 1 + src/autogen/app/views/hosts/_form.html.erb | 18 ++++- .../app/views/installtemplates/_form.html.erb | 1 - .../app/views/partials/_left-menu.html.erb | 3 +- .../config/environments/development.rb | 2 + src/autogen/config/routes.rb | 5 +- src/autogen/public/static-cloudinit/meta-data | 0 src/autogen/public/static-cloudinit/user-data | 64 +++++++++++++++++ .../public/static-cloudinit/vendor-data | 0 .../controllers/anshosts_controller_test.rb | 48 +++++++++++++ src/autogen/test/fixtures/anshosts.yml | 9 +++ src/autogen/test/models/anshost_test.rb | 7 ++ src/autogen/test/system/anshosts_test.rb | 43 ++++++++++++ 33 files changed, 430 insertions(+), 6 deletions(-) create mode 100644 src/autogen/app/controllers/anshosts_controller.rb create mode 100644 src/autogen/app/controllers/test_controller.rb create mode 100644 src/autogen/app/data/test.json create mode 100644 src/autogen/app/data/test.yml create mode 100644 src/autogen/app/helpers/anshosts_helper.rb create mode 100644 src/autogen/app/lib/filejson.rb create mode 100644 src/autogen/app/lib/fileyaml.rb create mode 100644 src/autogen/app/models/anshost.rb create mode 100644 src/autogen/app/views/anshosts/_anshost.html.erb create mode 100644 src/autogen/app/views/anshosts/_anshost.json.jbuilder create mode 100644 src/autogen/app/views/anshosts/_form.html.erb create mode 100644 src/autogen/app/views/anshosts/edit.html.erb create mode 100644 src/autogen/app/views/anshosts/index.html.erb create mode 100644 src/autogen/app/views/anshosts/index.json.jbuilder create mode 100644 src/autogen/app/views/anshosts/new.html.erb create mode 100644 src/autogen/app/views/anshosts/show.html.erb create mode 100644 src/autogen/app/views/anshosts/show.json.jbuilder create mode 100644 src/autogen/public/static-cloudinit/meta-data create mode 100644 src/autogen/public/static-cloudinit/user-data create mode 100644 src/autogen/public/static-cloudinit/vendor-data create mode 100644 src/autogen/test/controllers/anshosts_controller_test.rb create mode 100644 src/autogen/test/fixtures/anshosts.yml create mode 100644 src/autogen/test/models/anshost_test.rb create mode 100644 src/autogen/test/system/anshosts_test.rb diff --git a/src/autogen/Gemfile b/src/autogen/Gemfile index 3f5a875..f0ce2b6 100644 --- a/src/autogen/Gemfile +++ b/src/autogen/Gemfile @@ -70,3 +70,5 @@ gem "bulma-rails", "~> 0.9.4" gem "jquery-rails", "~> 4.6" gem "devise", "~> 4.9" + +gem "securerandom", "~> 0.3.1" diff --git a/src/autogen/Gemfile.lock b/src/autogen/Gemfile.lock index aefe4ff..f2d85a9 100644 --- a/src/autogen/Gemfile.lock +++ b/src/autogen/Gemfile.lock @@ -235,6 +235,7 @@ GEM rubyzip (2.3.2) sassc (2.4.0) ffi (~> 1.9) + securerandom (0.3.1) selenium-webdriver (4.17.0) base64 (~> 0.2) rexml (~> 3.2, >= 3.2.5) @@ -295,6 +296,7 @@ DEPENDENCIES mongoid (~> 8.1) puma (>= 5.0) rails (~> 7.1.3) + securerandom (~> 0.3.1) selenium-webdriver sprockets-rails stimulus-rails diff --git a/src/autogen/app/controllers/anshosts_controller.rb b/src/autogen/app/controllers/anshosts_controller.rb new file mode 100644 index 0000000..74eac7c --- /dev/null +++ b/src/autogen/app/controllers/anshosts_controller.rb @@ -0,0 +1,70 @@ +class AnshostsController < ApplicationController + before_action :set_anshost, only: %i[ show edit update destroy ] + + # GET /anshosts or /anshosts.json + def index + @anshosts = Anshost.all + end + + # GET /anshosts/1 or /anshosts/1.json + def show + end + + # GET /anshosts/new + def new + @anshost = Anshost.new + end + + # GET /anshosts/1/edit + def edit + end + + # POST /anshosts or /anshosts.json + def create + @anshost = Anshost.new(anshost_params) + + respond_to do |format| + if @anshost.save + format.html { redirect_to anshost_url(@anshost), notice: "Anshost was successfully created." } + format.json { render :show, status: :created, location: @anshost } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @anshost.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /anshosts/1 or /anshosts/1.json + def update + respond_to do |format| + if @anshost.update(anshost_params) + format.html { redirect_to anshost_url(@anshost), notice: "Anshost was successfully updated." } + format.json { render :show, status: :ok, location: @anshost } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @anshost.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /anshosts/1 or /anshosts/1.json + def destroy + @anshost.destroy! + + respond_to do |format| + format.html { redirect_to anshosts_url, notice: "Anshost was successfully destroyed." } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_anshost + @anshost = Anshost.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def anshost_params + params.require(:anshost).permit(:hostname, :var) + end +end diff --git a/src/autogen/app/controllers/hosts_controller.rb b/src/autogen/app/controllers/hosts_controller.rb index 11f13f1..98cd73d 100644 --- a/src/autogen/app/controllers/hosts_controller.rb +++ b/src/autogen/app/controllers/hosts_controller.rb @@ -134,6 +134,6 @@ class HostsController < ApplicationController # Only allow a list of trusted parameters through. def host_params - params.require(:host).permit(:uuid, :hostname, :ip, :status, :mac, :discover, :installed, :interface , :installtemplate, :site , :installtemplate_id, :site_id, :rootaccount_id, :mainaccount_id,:toinstall, :installip) + params.require(:host).permit(:uuid, :hostname, :ip, :status, :mac, :discover, :installed, :interface , :installtemplate, :site , :installtemplate_id, :site_id, :rootaccount_id, :mainaccount_id,:toinstall, :installip,:luskkey) end end diff --git a/src/autogen/app/controllers/test_controller.rb b/src/autogen/app/controllers/test_controller.rb new file mode 100644 index 0000000..09da515 --- /dev/null +++ b/src/autogen/app/controllers/test_controller.rb @@ -0,0 +1,24 @@ +class TestController < ApplicationController + def myip + @host = Host.new() + sourceip = client_ip + uuid="uuid-#{sourceip}" + hostname="new-#{sourceip}" + @template = Installtemplate.find_by(name:"Test Ubuntu - Desktop - nfs") + @site = Site.find_by(name:"default") + @account = Account.find_by(name:"ansible") + randomstring = SecureRandom.hex(12) + @host = Host.new(hostname: hostname,uuid: uuid, installip: sourceip, installtemplate: @template,site: @site, mac: "00:00:00:00:00:00", status: "discover", discover: true,installed: false, toinstall: false,rootaccount: @account, mainaccount: @account, luskkey: randomstring ) + @host.save! + + string = "You IP address is #{sourceip}" + render plain: string + end + def create + + end + private + def client_ip + request.remote_ip + end +end diff --git a/src/autogen/app/data/test.json b/src/autogen/app/data/test.json new file mode 100644 index 0000000..f571b5b --- /dev/null +++ b/src/autogen/app/data/test.json @@ -0,0 +1 @@ +{"var1":1,"var2":2,"sub":{"var1":3,"var2":4},"var3":3} \ No newline at end of file diff --git a/src/autogen/app/data/test.yml b/src/autogen/app/data/test.yml new file mode 100644 index 0000000..84eb7fe --- /dev/null +++ b/src/autogen/app/data/test.yml @@ -0,0 +1,10 @@ +--- +:title: Coffee +:ingredients: +- :ingredient_name: Water + :quantity: 8 + :unit_of_measurement: oz +- :ingredient_name: Coffee Grounds + :quantity: 1 + :unit_of_measurement: tbsp +:directions: Make coffee. \ No newline at end of file diff --git a/src/autogen/app/helpers/anshosts_helper.rb b/src/autogen/app/helpers/anshosts_helper.rb new file mode 100644 index 0000000..de8de85 --- /dev/null +++ b/src/autogen/app/helpers/anshosts_helper.rb @@ -0,0 +1,2 @@ +module AnshostsHelper +end diff --git a/src/autogen/app/lib/filejson.rb b/src/autogen/app/lib/filejson.rb new file mode 100644 index 0000000..73dbf84 --- /dev/null +++ b/src/autogen/app/lib/filejson.rb @@ -0,0 +1,16 @@ +class Filejson + + def initialize(path) + @path = path + file = File.read(@path) + @content = JSON.parse(file) + end + def get + @content + end + def save + File.open(@path, 'w') do |f| + f.write(@content.to_json) + end + end +end diff --git a/src/autogen/app/lib/fileyaml.rb b/src/autogen/app/lib/fileyaml.rb new file mode 100644 index 0000000..e9e33bb --- /dev/null +++ b/src/autogen/app/lib/fileyaml.rb @@ -0,0 +1,13 @@ +class Fileyaml + + def initialize(path) + @path = path + @content = YAML.load_file(@path) + end + def get + @content + end + def save + File.open(@path, "w") { |file| file.write(@content.to_yaml) } + end +end diff --git a/src/autogen/app/models/anshost.rb b/src/autogen/app/models/anshost.rb new file mode 100644 index 0000000..f3a2e9e --- /dev/null +++ b/src/autogen/app/models/anshost.rb @@ -0,0 +1,6 @@ +class Anshost + include Mongoid::Document + include Mongoid::Timestamps + field :hostname, type: String + field :var, type: Hash +end diff --git a/src/autogen/app/models/host.rb b/src/autogen/app/models/host.rb index d0b460d..39a3f02 100644 --- a/src/autogen/app/models/host.rb +++ b/src/autogen/app/models/host.rb @@ -14,6 +14,7 @@ class Host field :lastbootgenerated, type: String , default: '' field :lastinstallgenerated, type: String , default: '' field :lastpostinstallgenerated, type: String, default: '' + field :luskkey, type: String, default: '123456789123456789' belongs_to :installtemplate , class_name: "Installtemplate", inverse_of: :hostreferences belongs_to :site , class_name: "Site", inverse_of: :sitereferences belongs_to :rootaccount , class_name: "Account", inverse_of: :rootref diff --git a/src/autogen/app/views/anshosts/_anshost.html.erb b/src/autogen/app/views/anshosts/_anshost.html.erb new file mode 100644 index 0000000..518d09e --- /dev/null +++ b/src/autogen/app/views/anshosts/_anshost.html.erb @@ -0,0 +1,12 @@ +
+

+ Hostname: + <%= anshost.hostname %> +

+ +

+ Var: + <%= anshost.var %> +

+ +
diff --git a/src/autogen/app/views/anshosts/_anshost.json.jbuilder b/src/autogen/app/views/anshosts/_anshost.json.jbuilder new file mode 100644 index 0000000..1a4dd47 --- /dev/null +++ b/src/autogen/app/views/anshosts/_anshost.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! anshost, :id, :hostname, :var, :created_at, :updated_at +json.url anshost_url(anshost, format: :json) diff --git a/src/autogen/app/views/anshosts/_form.html.erb b/src/autogen/app/views/anshosts/_form.html.erb new file mode 100644 index 0000000..84deed2 --- /dev/null +++ b/src/autogen/app/views/anshosts/_form.html.erb @@ -0,0 +1,28 @@ +<%= form_with(model: anshost) do |form| %> + <% if anshost.errors.any? %> +
+

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

+ + +
+ <% end %> + +
+ <%= form.label :hostname, style: "display: block" %> + <%= form.text_field :hostname %> +
+ <% anshost.var.keys.each do |key| %> +
+ <%= form.label key, style: "display: block" %> + <%= form.text_field anshost.var[key] %> +
+ <% end %> + +
+ <%= form.submit %> +
+<% end %> diff --git a/src/autogen/app/views/anshosts/edit.html.erb b/src/autogen/app/views/anshosts/edit.html.erb new file mode 100644 index 0000000..481def0 --- /dev/null +++ b/src/autogen/app/views/anshosts/edit.html.erb @@ -0,0 +1,10 @@ +

Editing anshost

+ +<%= render "form", anshost: @anshost %> + +
+ +
+ <%= link_to "Show this anshost", @anshost %> | + <%= link_to "Back to anshosts", anshosts_path %> +
diff --git a/src/autogen/app/views/anshosts/index.html.erb b/src/autogen/app/views/anshosts/index.html.erb new file mode 100644 index 0000000..817c65a --- /dev/null +++ b/src/autogen/app/views/anshosts/index.html.erb @@ -0,0 +1,14 @@ +

<%= notice %>

+ +

Anshosts

+ +
+ <% @anshosts.each do |anshost| %> + <%= render anshost %> +

+ <%= link_to "Show this anshost", anshost %> +

+ <% end %> +
+ +<%= link_to "New anshost", new_anshost_path %> diff --git a/src/autogen/app/views/anshosts/index.json.jbuilder b/src/autogen/app/views/anshosts/index.json.jbuilder new file mode 100644 index 0000000..a32f23e --- /dev/null +++ b/src/autogen/app/views/anshosts/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @anshosts, partial: "anshosts/anshost", as: :anshost diff --git a/src/autogen/app/views/anshosts/new.html.erb b/src/autogen/app/views/anshosts/new.html.erb new file mode 100644 index 0000000..b4b7c8c --- /dev/null +++ b/src/autogen/app/views/anshosts/new.html.erb @@ -0,0 +1,9 @@ +

New anshost

+ +<%= render "form", anshost: @anshost %> + +
+ +
+ <%= link_to "Back to anshosts", anshosts_path %> +
diff --git a/src/autogen/app/views/anshosts/show.html.erb b/src/autogen/app/views/anshosts/show.html.erb new file mode 100644 index 0000000..cd588da --- /dev/null +++ b/src/autogen/app/views/anshosts/show.html.erb @@ -0,0 +1,10 @@ +

<%= notice %>

+ +<%= render @anshost %> + +
+ <%= link_to "Edit this anshost", edit_anshost_path(@anshost) %> | + <%= link_to "Back to anshosts", anshosts_path %> + + <%= button_to "Destroy this anshost", @anshost, method: :delete %> +
diff --git a/src/autogen/app/views/anshosts/show.json.jbuilder b/src/autogen/app/views/anshosts/show.json.jbuilder new file mode 100644 index 0000000..062c5c6 --- /dev/null +++ b/src/autogen/app/views/anshosts/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "anshosts/anshost", anshost: @anshost diff --git a/src/autogen/app/views/hosts/_form.html.erb b/src/autogen/app/views/hosts/_form.html.erb index 67aca7b..f79f910 100644 --- a/src/autogen/app/views/hosts/_form.html.erb +++ b/src/autogen/app/views/hosts/_form.html.erb @@ -92,6 +92,19 @@ +
+
+ +
+
+
+
+ <%= form.text_field :luskkey , { class: "input"} %> +
+
+
+
+
@@ -145,6 +158,7 @@ <%= form.collection_select :mainaccount_id, Account.all, :id, :name %>
+
<%= form.label :discover, class: "checkbox" %> @@ -162,9 +176,11 @@
<%= link_to "Return", "/hosts", class: "button is-success" %> - <%= button_to "Destroy", @host, method: :delete, class: "button is-danger is-pulled-right" %> +
<% end %> + <%= button_to " Destroy ", @host, method: :delete, class: "button is-danger" %> +
diff --git a/src/autogen/app/views/installtemplates/_form.html.erb b/src/autogen/app/views/installtemplates/_form.html.erb index fd5d876..fa35e88 100644 --- a/src/autogen/app/views/installtemplates/_form.html.erb +++ b/src/autogen/app/views/installtemplates/_form.html.erb @@ -108,5 +108,4 @@ <% end %> -<%= button_to " Destroy ", @installtemplate, method: :delete, class: "button is-danger" %> diff --git a/src/autogen/app/views/partials/_left-menu.html.erb b/src/autogen/app/views/partials/_left-menu.html.erb index 9e5c887..d834943 100644 --- a/src/autogen/app/views/partials/_left-menu.html.erb +++ b/src/autogen/app/views/partials/_left-menu.html.erb @@ -8,7 +8,8 @@ <%= link_to "Scripts" , scripts_path %> <%= link_to "Templates" , installtemplates_path %> <%= link_to "Sites" , sites_path %> - <%= link_to "Account" , accounts_path %> + <%= link_to "Account" , accounts_path %> + <%= link_to "Inventory" , anshosts_path %> diff --git a/src/autogen/config/environments/development.rb b/src/autogen/config/environments/development.rb index a695867..b765f77 100644 --- a/src/autogen/config/environments/development.rb +++ b/src/autogen/config/environments/development.rb @@ -64,4 +64,6 @@ Rails.application.configure do # Raise error when a before_action's only/except options reference missing actions config.action_controller.raise_on_missing_callback_actions = true + config.web_console.whitelisted_ips = '0.0.0.0/0' + end diff --git a/src/autogen/config/routes.rb b/src/autogen/config/routes.rb index cb934ca..35bca83 100644 --- a/src/autogen/config/routes.rb +++ b/src/autogen/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :anshosts devise_for :users resources :scripts resources :sites @@ -33,6 +34,6 @@ Rails.application.routes.draw do get '/api/host/cloudinit/:uuid/meta-data', to: "engine#generate_metadata", defaults: { format: 'text' } get '/api/host/cloudinit/:uuid/vendor-data', to: "engine#generate_metadata", defaults: { format: 'text' } - - + # test + get '/test/myip', to: "test#myip", defaults: { format: 'text' } end diff --git a/src/autogen/public/static-cloudinit/meta-data b/src/autogen/public/static-cloudinit/meta-data new file mode 100644 index 0000000..e69de29 diff --git a/src/autogen/public/static-cloudinit/user-data b/src/autogen/public/static-cloudinit/user-data new file mode 100644 index 0000000..f520ec7 --- /dev/null +++ b/src/autogen/public/static-cloudinit/user-data @@ -0,0 +1,64 @@ +#cloud-config +autoinstall: + version: 1 + packages: + - ubuntu-desktop + snaps: + - name: firefox + - name: gnome-3-38-2004 + - name: gtk-common-themes + - name: snap-store + - name: snapd-desktop-integration + interactive-sections: + - identity + keyboard: + layout: fr + toggle: null + variant: '' + locale: fr_FR.UTF-8 + storage: + layout: + name: lvm + password: touch + ssh: + install-server: true + # option "allow-pw" defaults to `true` if authorized_keys is empty, `false` otherwise. + allow-pw: false + updates: security + # Ubuntu Desktop uses the hwe flavor kernel by default. + early-commands: + - echo 'linux-generic-hwe-22.04' > /run/kernel-meta-package + # "[late-commands] are run in the installer environment with the installed system mounted at /target." + late-commands: + # randomly generate the hostname & show the IP at boot + - echo ubuntu-host-$(openssl rand -hex 3) > /target/etc/hostname + # dump the IP out at login screen + - echo "Ubuntu 22.04 LTS \nIP - $(hostname -I)\n" > /target/etc/issue + # Let NetworkManager handle network + - rm /target/etc/netplan/00-installer-config*yaml + - >- + printf "network:\n version: 2\n renderer: NetworkManager" + > /target/etc/netplan/01-network-manager-all.yaml + # shut-down the host to avoid an infinite installer loop + - shutdown -h now + + user-data: + disable_root: true + timezone: Europe/Paris + package_upgrade: false + users: + - name: useritlu + primary_group: users + groups: sudo + lock_passwd: false + # don't need PW since using SSH, leaving this in though... + # password is "changeme" - created with `docker run -it --rm alpine mkpasswd --method=SHA-512` + passwd: "$5$IWwNqL9VUSDoc4Jv$DEUGR.cZQcbz/QvdCOmU13fX5ZW0rANg8LqkAtX3nBA" + shell: /bin/bash + # use cat ~/.ssh/id_rsa.pub or generate to get your public key + ssh_authorized_keys: + - "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC14slyp/JGv9iqLH4D94x+7v4PB/ec0YbLUPexdBip6OJaflbmp3s25WJ+oyO6U78Ee0jZUZt0TapYozyNx9UksP9JhirwKeNJnQSzSX0RKc6kQffoCgWHZmnzuoalEzaE7XyH+K8wP+hKi052ak9yR7XWDp6CG3V1Qpyq80VD1XNUzEL2xkITGQ6KojxrOJ1O0A9ISRu1t85Ul2N0syIylE2Ukvns1/NkArhC2g8N8T5XxPq39AUH78A3I0/kHowIzW9BpPVwim0tJTLSVNnVqq1NPG+gi1XvrXKzO/jb4kT01tnMG9vKcYqdH4g0y01ADEcCgMo1jGAjwq6gPLqT imported-openssh-key" + sudo: ALL=(ALL) NOPASSWD:ALL + # shutdown after first host initial provisioning + power_state: + mode: poweroff \ No newline at end of file diff --git a/src/autogen/public/static-cloudinit/vendor-data b/src/autogen/public/static-cloudinit/vendor-data new file mode 100644 index 0000000..e69de29 diff --git a/src/autogen/test/controllers/anshosts_controller_test.rb b/src/autogen/test/controllers/anshosts_controller_test.rb new file mode 100644 index 0000000..fb53540 --- /dev/null +++ b/src/autogen/test/controllers/anshosts_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class AnshostsControllerTest < ActionDispatch::IntegrationTest + setup do + @anshost = anshosts(:one) + end + + test "should get index" do + get anshosts_url + assert_response :success + end + + test "should get new" do + get new_anshost_url + assert_response :success + end + + test "should create anshost" do + assert_difference("Anshost.count") do + post anshosts_url, params: { anshost: { hostname: @anshost.hostname, var: @anshost.var } } + end + + assert_redirected_to anshost_url(Anshost.last) + end + + test "should show anshost" do + get anshost_url(@anshost) + assert_response :success + end + + test "should get edit" do + get edit_anshost_url(@anshost) + assert_response :success + end + + test "should update anshost" do + patch anshost_url(@anshost), params: { anshost: { hostname: @anshost.hostname, var: @anshost.var } } + assert_redirected_to anshost_url(@anshost) + end + + test "should destroy anshost" do + assert_difference("Anshost.count", -1) do + delete anshost_url(@anshost) + end + + assert_redirected_to anshosts_url + end +end diff --git a/src/autogen/test/fixtures/anshosts.yml b/src/autogen/test/fixtures/anshosts.yml new file mode 100644 index 0000000..0d41e62 --- /dev/null +++ b/src/autogen/test/fixtures/anshosts.yml @@ -0,0 +1,9 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + hostname: MyString + var: + +two: + hostname: MyString + var: diff --git a/src/autogen/test/models/anshost_test.rb b/src/autogen/test/models/anshost_test.rb new file mode 100644 index 0000000..69abd90 --- /dev/null +++ b/src/autogen/test/models/anshost_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class AnshostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/src/autogen/test/system/anshosts_test.rb b/src/autogen/test/system/anshosts_test.rb new file mode 100644 index 0000000..de58e6f --- /dev/null +++ b/src/autogen/test/system/anshosts_test.rb @@ -0,0 +1,43 @@ +require "application_system_test_case" + +class AnshostsTest < ApplicationSystemTestCase + setup do + @anshost = anshosts(:one) + end + + test "visiting the index" do + visit anshosts_url + assert_selector "h1", text: "Anshosts" + end + + test "should create anshost" do + visit anshosts_url + click_on "New anshost" + + fill_in "Hostname", with: @anshost.hostname + fill_in "Var", with: @anshost.var + click_on "Create Anshost" + + assert_text "Anshost was successfully created" + click_on "Back" + end + + test "should update Anshost" do + visit anshost_url(@anshost) + click_on "Edit this anshost", match: :first + + fill_in "Hostname", with: @anshost.hostname + fill_in "Var", with: @anshost.var + click_on "Update Anshost" + + assert_text "Anshost was successfully updated" + click_on "Back" + end + + test "should destroy Anshost" do + visit anshost_url(@anshost) + click_on "Destroy this anshost", match: :first + + assert_text "Anshost was successfully destroyed" + end +end