diff --git a/Gemfile b/Gemfile index 3442c17..70b2995 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,8 @@ source 'https://rubygems.org' -gem 'rails', '4.0.6' -gem 'mysql2', '0.3.17' gem 'syslogger', git: 'https://github.com/jbussdieker/syslogger.git', :branch => 'implement_log_formatter' +gem 'rails', '4.2.5' +gem 'mysql2', '0.3.18' gem 'puppet' gem 'mcollective-client' gem 'chartkick' @@ -15,13 +15,15 @@ gem 'sass-rails', '~> 4.0.0' gem 'coffee-rails', '~> 4.0.0' gem 'uglifier', '>= 1.0.3' gem 'jquery-rails' -gem 'awesome_print', require:"ap" +gem 'awesome_print' # attr_accessible` is extracted out of Rails into a gem. # Please use new recommended protection model for params(strong_parameters) # or add `protected_attributes` to your Gemfile to use old one gem 'protected_attributes' +gem 'responders', '~> 2.0' + # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', :platforms => :ruby @@ -29,6 +31,7 @@ group :development, :test do gem 'rspec-rails' gem 'factory_girl_rails' gem 'coveralls', require: false + gem 'web-console', '~> 2.0' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 80efd9d..0f9bd4c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,35 +9,47 @@ GEM remote: https://rubygems.org/ specs: CFPropertyList (2.2.8) - actionmailer (4.0.6) - actionpack (= 4.0.6) - mail (~> 2.5.4) - actionpack (4.0.6) - activesupport (= 4.0.6) - builder (~> 3.1.0) - erubis (~> 2.7.0) - rack (~> 1.5.2) + actionmailer (4.2.5) + actionpack (= 4.2.5) + actionview (= 4.2.5) + activejob (= 4.2.5) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.5) + actionview (= 4.2.5) + activesupport (= 4.2.5) + rack (~> 1.6) rack-test (~> 0.6.2) - activemodel (4.0.6) - activesupport (= 4.0.6) - builder (~> 3.1.0) - activerecord (4.0.6) - activemodel (= 4.0.6) - activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.6) - arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.4) - activesupport (4.0.6) - i18n (~> 0.6, >= 0.6.9) - minitest (~> 4.2) - multi_json (~> 1.3) - thread_safe (~> 0.1) - tzinfo (~> 0.3.37) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.5) + activesupport (= 4.2.5) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (4.2.5) + activesupport (= 4.2.5) + globalid (>= 0.3.0) + activemodel (4.2.5) + activesupport (= 4.2.5) + builder (~> 3.1) + activerecord (4.2.5) + activemodel (= 4.2.5) + activesupport (= 4.2.5) + arel (~> 6.0) + activesupport (4.2.5) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) addressable (2.5.0) public_suffix (~> 2.0, >= 2.0.2) - arel (4.0.2) - awesome_print (1.7.0) - builder (3.1.4) + arel (6.0.4) + binding_of_caller (0.7.2) + debug_inspector (>= 0.0.1) + builder (3.2.3) capybara (2.11.0) addressable mime-types (>= 1.16) @@ -62,6 +74,7 @@ GEM thor (~> 0.19.1) tins (~> 1.6) database_cleaner (1.5.3) + debug_inspector (0.0.2) diff-lcs (1.2.5) docile (1.1.5) erubis (2.7.0) @@ -73,38 +86,52 @@ GEM factory_girl_rails (4.8.0) factory_girl (~> 4.8.0) railties (>= 3.0.0) - faker (1.7.2) + faker (1.7.3) i18n (~> 0.5) ffi (1.9.17) - groupdate (3.1.1) + globalid (0.3.7) + activesupport (>= 4.1.0) + groupdate (3.2.0) activesupport (>= 3) - hiera (3.2.2) + hiera (3.3.1) hike (1.2.3) - i18n (0.7.0) - jquery-rails (3.1.4) - railties (>= 3.0, < 5.0) + i18n (0.8.1) + jquery-rails (4.2.2) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (2.0.3) + json (1.8.6) json_pure (1.8.6) - kaminari (0.17.0) - actionpack (>= 3.0.0) - activesupport (>= 3.0.0) + kaminari (1.0.1) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.0.1) + kaminari-activerecord (= 1.0.1) + kaminari-core (= 1.0.1) + kaminari-actionview (1.0.1) + actionview + kaminari-core (= 1.0.1) + kaminari-activerecord (1.0.1) + activerecord + kaminari-core (= 1.0.1) + kaminari-core (1.0.1) kgio (2.11.0) - mail (2.5.4) - mime-types (~> 1.16) - treetop (~> 1.4.8) - mcollective-client (2.9.1) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.4) + mime-types (>= 1.16, < 4) + mcollective-client (2.10.2) json stomp systemu - mime-types (1.25.1) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) mini_portile2 (2.1.0) - minitest (4.7.5) + minitest (5.10.1) multi_json (1.12.1) - mysql2 (0.3.17) - nokogiri (1.7.0.1) + mysql2 (0.3.18) + nokogiri (1.6.8.1) mini_portile2 (~> 2.1.0) - polyglot (0.3.5) protected_attributes (1.1.3) activemodel (>= 4.0.1, < 5.0) public_suffix (2.0.5) @@ -113,25 +140,38 @@ GEM facter (> 2.0, < 4) hiera (>= 2.0, < 4) json_pure (~> 1.8) - rack (1.5.5) + rack (1.6.5) rack-test (0.6.3) rack (>= 1.0) - rails (4.0.6) - actionmailer (= 4.0.6) - actionpack (= 4.0.6) - activerecord (= 4.0.6) - activesupport (= 4.0.6) + rails (4.2.5) + actionmailer (= 4.2.5) + actionpack (= 4.2.5) + actionview (= 4.2.5) + activejob (= 4.2.5) + activemodel (= 4.2.5) + activerecord (= 4.2.5) + activesupport (= 4.2.5) bundler (>= 1.3.0, < 2.0) - railties (= 4.0.6) - sprockets-rails (~> 2.0) + railties (= 4.2.5) + sprockets-rails rails-bootstrap (3.0.0.4) - railties (4.0.6) - actionpack (= 4.0.6) - activesupport (= 4.0.6) + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.8) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (4.2.5) + actionpack (= 4.2.5) + activesupport (= 4.2.5) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) raindrops (0.17.0) rake (12.0.0) + responders (2.3.0) + railties (>= 4.2.0, < 5.1) rspec-core (3.5.4) rspec-support (~> 3.5.0) rspec-expectations (3.5.0) @@ -182,16 +222,18 @@ GEM thread_safe (0.3.5) tilt (1.4.1) tins (1.13.0) - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) tzinfo (0.3.52) uglifier (3.0.4) execjs (>= 0.3.0, < 3) unicorn (5.2.0) kgio (~> 2.6) raindrops (~> 0.7) - websocket (1.2.3) + web-console (2.3.0) + activemodel (>= 4.0) + binding_of_caller (>= 0.7.2) + railties (>= 4.0) + sprockets-rails (>= 2.0, < 4.0) + websocket (1.2.4) xpath (2.0.0) nokogiri (~> 1.3) @@ -211,14 +253,19 @@ DEPENDENCIES jquery-rails kaminari mcollective-client - mysql2 (= 0.3.17) + mysql2 (= 0.3.18) protected_attributes puppet - rails (= 4.0.6) + rails (= 4.2.5) rails-bootstrap (~> 3.0.0) + responders (~> 2.0) rspec-rails sass-rails (~> 4.0.0) selenium-webdriver syslogger! uglifier (>= 1.0.3) unicorn + web-console (~> 2.0) + +BUNDLED WITH + 1.13.6 diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index 97a165d..fa03b58 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb @@ -87,7 +87,7 @@ def status_history def resource_times @report = @node.reports.order("time DESC").first if @report - @metrics = @report.metrics.where(:category => "Time") + @metrics = @report.metrics.where(:category => "Time").to_a @metrics.reject! {|n| n.name == "Total"} @metrics = @metrics.collect {|n| [n.name, n.value]} else diff --git a/app/controllers/parameters_controller.rb b/app/controllers/parameters_controller.rb index da2f72f..658d3ba 100644 --- a/app/controllers/parameters_controller.rb +++ b/app/controllers/parameters_controller.rb @@ -2,7 +2,7 @@ class ParametersController < ApplicationController helper_method :sort_column, :sort_direction def index - @parameters = Parameter.where(parameterable_id: nil).order(sort_column + " " + sort_direction) + @parameters = Parameter.where(parameterable_id: nil).order(sort_column + " " + sort_direction).to_a render_collection(@parameters) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8f0b166..e06ab59 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -24,4 +24,14 @@ def current_url(new_params) string = options.map{ |k,v| "#{k}=#{v}" }.join("&") request.fullpath.split("?")[0] + "?" + string end + + def link_to_function(name, *args, &block) + html_options = args.extract_options!.symbolize_keys + + function = block_given? ? update_page(&block) : args[0] || '' + onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;" + href = html_options[:href] || '#' + + content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick)) + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 613eaeb..518e781 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -29,6 +29,16 @@
  • <%= link_to "Parameters", parameters_path %>
  • <%= link_to "Reports", reports_path %>
  • + + diff --git a/config/application.rb b/config/application.rb index f1c8963..39773ae 100644 --- a/config/application.rb +++ b/config/application.rb @@ -4,9 +4,7 @@ if defined?(Bundler) # If you precompile assets before deploying to production, use this line - Bundler.require(*Rails.groups) - # If you want your assets lazily compiled in production, use this line - # Bundler.require(:default, :assets, Rails.env) + Bundler.require(:default, Rails.env) end module Enc @@ -42,21 +40,9 @@ class Application < Rails::Application # Enable escaping HTML in JSON. config.active_support.escape_html_entities_in_json = true - # Use SQL instead of Active Record's schema dumper when creating the database. - # This is necessary if your schema can't be completely dumped by the schema dumper, - # like if you have constraints or database-specific column types - # config.active_record.schema_format = :sql - - # Enforce whitelist mode for mass assignment. - # This will create an empty whitelist of attributes available for mass-assignment for all models - # in your app. As such, your models will need to explicitly whitelist or blacklist accessible - # parameters by using an attr_accessible or attr_protected declaration. - config.active_record.whitelist_attributes = true - - # Enable the asset pipeline - config.assets.enabled = true - # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' + + config.active_record.raise_in_transactional_callbacks = true end end diff --git a/config/environments/development.rb b/config/environments/development.rb index a5bf402..d602256 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -12,15 +12,22 @@ config.consider_all_requests_local = true config.action_controller.perform_caching = false + # Compress JavaScripts and CSS + config.assets.js_compressor = :uglifier + # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = false # Print deprecation notices to the Rails logger config.active_support.deprecation = :log - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict + # Raise an error on page load if there are pending migrations + config.active_record.migration_error = :page_load # Expands the lines which load the assets config.assets.debug = true + + config.logger = Logger.new(STDOUT) + config.logger.level = :debug + config.log_level = :debug end diff --git a/config/environments/prod.rb b/config/environments/prod.rb index 76c4bb1..d5ab2cd 100644 --- a/config/environments/prod.rb +++ b/config/environments/prod.rb @@ -11,7 +11,7 @@ config.action_controller.perform_caching = true # Disable Rails's static asset server (Apache or nginx will already do this) - config.serve_static_assets = false + config.serve_static_assets = true # Compress JavaScripts and CSS config.assets.js_compressor = :uglifier @@ -64,11 +64,10 @@ config.active_support.deprecation = :notify config.serve_static_assets = true - config.assets.compile = false config.paths['config/database'] = '/etc/enc_dashboard/database.yml' if File.exists? '/etc/enc_dashboard/database.yml' - # Setup custom logger to syslog - config.logger = Syslogger.new("enc_dashboard", Syslog::LOG_PID | Syslog::LOG_CONS, Syslog::LOG_LOCAL5) - config.logger.level = Logger::ERROR - config.logger.level = Logger::DEBUG if File.exists?"/tmp/moov_debug_prod" + # Setup custom logger to stdout and log level to debug + config.logger = Logger.new(STDOUT) + config.logger.level = :debug + config.log_level = :debug end diff --git a/config/environments/production.rb b/config/environments/production.rb index d100d72..704ffbe 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -11,7 +11,7 @@ config.action_controller.perform_caching = true # Disable Rails's static asset server (Apache or nginx will already do this) - config.serve_static_assets = false + config.serve_static_assets = true # Compress JavaScripts and CSS config.assets.js_compressor = :uglifier @@ -62,4 +62,9 @@ # Send deprecation notices to registered listeners config.active_support.deprecation = :notify + + # Setup custom logger to stdout and log level to debug + config.logger = Logger.new(STDOUT) + config.logger.level = :debug + config.log_level = :debug end diff --git a/config/environments/stage.rb b/config/environments/stage.rb index cb39d68..b37caf9 100644 --- a/config/environments/stage.rb +++ b/config/environments/stage.rb @@ -18,8 +18,7 @@ # Print deprecation notices to the Rails logger config.active_support.deprecation = :log - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict + config.assets.js_compressor = :uglifier # Expands the lines which load the assets config.assets.debug = true diff --git a/config/environments/test.rb b/config/environments/test.rb index 69f771b..3f37da3 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -28,9 +28,6 @@ # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict - # Print deprecation notices to the stderr config.active_support.deprecation = :stderr end diff --git a/config/routes.rb b/config/routes.rb index c413289..db6793e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -32,6 +32,7 @@ end resources :parameters, only: [:index, :new, :create] root :to => 'nodes#index' + # Rails 4.0 requires that routes using match must specify the request method # match 'moov_check' => "home#moov_check" get 'moov_check' => 'home#moov_check' diff --git a/db/schema.rb b/db/schema.rb index 2c42a1c..ab58670 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -13,104 +13,104 @@ ActiveRecord::Schema.define(version: 20160503213802) do - create_table "metrics", force: true do |t| - t.integer "report_id", null: false - t.string "category" - t.string "name" - t.decimal "value", precision: 12, scale: 6 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table "metrics", force: :cascade do |t| + t.integer "report_id", limit: 4, null: false + t.string "category", limit: 255 + t.string "name", limit: 255 + t.decimal "value", precision: 12, scale: 6 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "metrics", ["report_id"], name: "index_metrics_on_report_id", using: :btree - create_table "node_class_memberships", force: true do |t| - t.integer "node_id" - t.integer "node_class_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table "node_class_memberships", force: :cascade do |t| + t.integer "node_id", limit: 4 + t.integer "node_class_id", limit: 4 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "node_classes", force: true do |t| - t.string "name", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table "node_classes", force: :cascade do |t| + t.string "name", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "node_classes", ["name"], name: "index_node_classes_on_name", unique: true, using: :btree - create_table "node_group_memberships", force: true do |t| - t.integer "node_id" - t.integer "node_group_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table "node_group_memberships", force: :cascade do |t| + t.integer "node_id", limit: 4 + t.integer "node_group_id", limit: 4 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "node_group_memberships", ["node_group_id"], name: "index_node_group_memberships_on_node_group_id", using: :btree - create_table "node_groups", force: true do |t| - t.string "name", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table "node_groups", force: :cascade do |t| + t.string "name", limit: 255, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "node_groups", ["name"], name: "index_node_groups_on_name", unique: true, using: :btree - create_table "nodes", force: true do |t| - t.string "name", null: false - t.text "description" + create_table "nodes", force: :cascade do |t| + t.string "name", limit: 255, null: false + t.text "description", limit: 65535 t.datetime "reported_at" - t.integer "last_apply_report_id" - t.string "status" - t.boolean "hidden", default: false - t.integer "last_inspect_report_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "environment" + t.integer "last_apply_report_id", limit: 4 + t.string "status", limit: 255 + t.boolean "hidden", default: false + t.integer "last_inspect_report_id", limit: 4 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "environment", limit: 255 end add_index "nodes", ["name"], name: "index_nodes_on_name", unique: true, using: :btree - create_table "parameters", force: true do |t| - t.string "key" - t.text "value" - t.integer "parameterable_id" - t.string "parameterable_type" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + create_table "parameters", force: :cascade do |t| + t.string "key", limit: 255 + t.text "value", limit: 65535 + t.integer "parameterable_id", limit: 4 + t.string "parameterable_type", limit: 255 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "report_logs", force: true do |t| - t.integer "report_id" - t.string "level" - t.text "message" + create_table "report_logs", force: :cascade do |t| + t.integer "report_id", limit: 4 + t.string "level", limit: 255 + t.text "message", limit: 65535 t.datetime "time" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "source" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "source", limit: 255 end add_index "report_logs", ["report_id"], name: "index_report_logs_on_report_id", using: :btree - create_table "reports", force: true do |t| - t.integer "node_id" - t.string "status" - t.string "environment" + create_table "reports", force: :cascade do |t| + t.integer "node_id", limit: 4 + t.string "status", limit: 255 + t.string "environment", limit: 255 t.datetime "time" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "reports", ["node_id"], name: "index_reports_on_node_id", using: :btree - create_table "resource_statuses", force: true do |t| - t.integer "report_id" + create_table "resource_statuses", force: :cascade do |t| + t.integer "report_id", limit: 4 t.boolean "failed" t.boolean "skipped" t.boolean "is_changed" - t.text "title" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.text "title", limit: 65535 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "resource_statuses", ["report_id"], name: "index_resource_statuses_on_report_id", using: :btree diff --git a/spec/factories/node.rb b/spec/factories/node.rb index 39405cb..b56326a 100644 --- a/spec/factories/node.rb +++ b/spec/factories/node.rb @@ -37,7 +37,7 @@ end factory :node_with_reports, parent: :node do - ignore do + ransient do report_count 5 end diff --git a/spec/factories/report.rb b/spec/factories/report.rb index 8f31bf2..0fde8a9 100644 --- a/spec/factories/report.rb +++ b/spec/factories/report.rb @@ -9,7 +9,7 @@ end factory :report_with_dependents, parent: :full_report do - ignore do + ransient do metric_count 5 report_log_count 5 resource_status_count 5