diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index c360f27..cabb773 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -41,7 +41,10 @@ def create end end - rep = Report.create report: JSON.generate(ary) + rep = Report.create report: JSON.generate(ary), + ruby: input["ruby"], + os: input["os"], + arch: input["arch"] options = input["options"] || {} diff --git a/db/migrate/20231006184214_add_attributes_to_reports.rb b/db/migrate/20231006184214_add_attributes_to_reports.rb new file mode 100644 index 0000000..cca10a5 --- /dev/null +++ b/db/migrate/20231006184214_add_attributes_to_reports.rb @@ -0,0 +1,7 @@ +class AddAttributesToReports < ActiveRecord::Migration[7.0] + def change + add_column :reports, :ruby, :string + add_column :reports, :os, :string + add_column :reports, :arch, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 0252bad..2c206f0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2,24 +2,26 @@ # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# This file is the source Rails uses to define your schema when running `rails -# db:schema:load`. When creating a new database, `rails db:schema:load` tends to +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to # be faster and is potentially less error prone than running all of your # migrations from scratch. Old migrations may fail to apply correctly if those # migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2016_04_13_035657) do - +ActiveRecord::Schema[7.0].define(version: 2023_10_06_184214) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" create_table "reports", id: :serial, force: :cascade do |t| t.text "report" t.boolean "compare" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false + t.string "ruby" + t.string "os" + t.string "arch" end end diff --git a/test/controllers/reports_controller_test.rb b/test/controllers/reports_controller_test.rb index d40afa7..8f9b34c 100644 --- a/test/controllers/reports_controller_test.rb +++ b/test/controllers/reports_controller_test.rb @@ -64,7 +64,7 @@ class ReportsControllerTest < ActionController::TestCase }] } DATA - + post :create, body: data assert_equal "400", @response.code @@ -79,10 +79,39 @@ class ReportsControllerTest < ActionController::TestCase }] } DATA - + post :create, body: data assert_equal "400", @response.code + end + + test "environment variables are sent, processed, and saved" do + data = { + "ruby" => "3.2.1", + "os" => "Linux", + "arch" => "x86_64", + "entries" => [ + { + "name" => "test", + "ips" => 10.1, + "central_tendency" => 10.1, + "error" => 23666, + "stddev" => 0.3, + "microseconds" => 3322, + "iterations" => 221, + "cycles" => 16 + } + ] + } + + post :create, body: data.to_json + + rep = JSON.parse @response.body + + report = Report.find_from_short_id rep["id"] + assert_equal "3.2.1", report.ruby + assert_equal "Linux", report.os + assert_equal "x86_64", report.arch end end