Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 5b20e0cbc500431fce7d5d19dc11290155b320f1 Mon Sep 17 00:00:00 2001
- From: Gregory Durelle <gdurelle@protonmail.com>
- Date: Sun, 24 Jun 2018 01:45:08 +0200
- Subject: [PATCH] My submission
- XOV: v1
- add a gem for testing, add tests, fix typo, add request to return avg/min/max/etc
- ---
- Gemfile | 3 ++-
- Gemfile.lock | 5 +++++
- app/controllers/one_day_electricities_controller.rb | 5 +++++
- app/controllers/one_hour_electricities_controller.rb | 2 +-
- config/database.yml | 5 +++--
- .../one_day_electricities_controller_spec.rb | 18 ++++++++++++++++++
- .../one_hour_electricities_controller_spec.rb | 13 +++++++++++++
- tmp/pids/server.pid | 1 +
- 8 files changed, 48 insertions(+), 4 deletions(-)
- create mode 100644 spec/controllers/one_day_electricities_controller_spec.rb
- create mode 100644 spec/controllers/one_hour_electricities_controller_spec.rb
- create mode 100644 tmp/pids/server.pid
- diff --git a/Gemfile b/Gemfile
- index ea2da3b..f494d1a 100755
- --- a/Gemfile
- +++ b/Gemfile
- @@ -17,4 +17,5 @@ group :test do
- gem 'factory_bot_rails'
- gem 'shoulda'
- gem 'simplecov', require: false
- -end
- \ No newline at end of file
- + gem 'rails-controller-testing'
- +end
- diff --git a/Gemfile.lock b/Gemfile.lock
- index 566cf14..71ed6b0 100755
- --- a/Gemfile.lock
- +++ b/Gemfile.lock
- @@ -92,6 +92,10 @@ GEM
- bundler (>= 1.3.0)
- railties (= 5.1.5)
- sprockets-rails (>= 2.0.0)
- + rails-controller-testing (1.0.2)
- + actionpack (~> 5.x, >= 5.0.1)
- + actionview (~> 5.x, >= 5.0.1)
- + activesupport (~> 5.x)
- rails-dom-testing (2.0.3)
- activesupport (>= 4.2.0)
- nokogiri (>= 1.6)
- @@ -160,6 +164,7 @@ DEPENDENCIES
- puma
- rack-cors
- rails (= 5.1.5)
- + rails-controller-testing
- rspec-rails (~> 3.7.2)
- shoulda
- simplecov
- diff --git a/app/controllers/one_day_electricities_controller.rb b/app/controllers/one_day_electricities_controller.rb
- index a48c2a0..646e969 100755
- --- a/app/controllers/one_day_electricities_controller.rb
- +++ b/app/controllers/one_day_electricities_controller.rb
- @@ -4,6 +4,11 @@ class OneDayElectricitiesController < ApplicationController
- # GET /one_day_electricities
- # GET /one_day_electricities.json
- def index
- + @one_day_electricities = OneHourElectricity.where(panel: @panel)
- + .where("DATE(hour) < ?", Date.today).select("DATE(hour) as day, SUM(kilowatts) as sum, \
- + MIN(kilowatts) as min, MAX(kilowatts) as max, \
- + AVG(kilowatts) as average").group("DATE(hour)")
- +
- end
- private
- diff --git a/app/controllers/one_hour_electricities_controller.rb b/app/controllers/one_hour_electricities_controller.rb
- index b2178cc..5c3eef5 100755
- --- a/app/controllers/one_hour_electricities_controller.rb
- +++ b/app/controllers/one_hour_electricities_controller.rb
- @@ -28,7 +28,7 @@ class OneHourElectricitiesController < ApplicationController
- private
- def set_panel
- - @panel = Panel.find_by_serial params[:banel_serial]
- + @panel = Panel.find_by_serial params[:panel_serial]
- end
- # Whitelisting one-hour-electricity parameters
- diff --git a/config/database.yml b/config/database.yml
- index b9404c5..06a8242 100755
- --- a/config/database.yml
- +++ b/config/database.yml
- @@ -2,9 +2,10 @@ default: &default
- adapter: mysql2
- encoding: utf8
- username: root
- + password: r0OT_mysql
- host: localhost
- port: 3306
- - reconnect: false
- + # reconnect: false
- pool: 5
- timeout: 5000
- @@ -21,4 +22,4 @@ test:
- production:
- <<: *default
- - database: cross-solar-production
- \ No newline at end of file
- + database: cross-solar-production
- diff --git a/spec/controllers/one_day_electricities_controller_spec.rb b/spec/controllers/one_day_electricities_controller_spec.rb
- new file mode 100644
- index 0000000..419dbf0
- --- /dev/null
- +++ b/spec/controllers/one_day_electricities_controller_spec.rb
- @@ -0,0 +1,18 @@
- +require 'rails_helper'
- +
- +RSpec.describe OneDayElectricitiesController, type: :controller do
- + render_views
- +
- + describe "GET index" do
- + let!(:panel) { FactoryBot.create :panel }
- + it "assigns @panel" do
- + get :index, format: :json, params: { panel_serial: panel.serial }
- + expect(assigns(:panel)).to eq(panel)
- + end
- +
- + it "renders the index template" do
- + get :index, format: :json, params: { panel_serial: panel.serial }
- + expect(response).to render_template("index")
- + end
- + end
- +end
- diff --git a/spec/controllers/one_hour_electricities_controller_spec.rb b/spec/controllers/one_hour_electricities_controller_spec.rb
- new file mode 100644
- index 0000000..b3f819b
- --- /dev/null
- +++ b/spec/controllers/one_hour_electricities_controller_spec.rb
- @@ -0,0 +1,13 @@
- +require 'rails_helper'
- +
- +RSpec.describe OneHourElectricitiesController, type: :controller do
- + describe "GET index" do
- + let!(:one_hour_electricity) { FactoryBot.create :one_hour_electricity }
- + let(:panel) { one_hour_electricity.panel }
- + it "assigns @panel" do
- + get :index, format: :json, params: { panel_serial: panel.serial }
- + expect(assigns(:panel)).to eq(panel)
- + expect(assigns(:one_hour_electricities)).to eq([one_hour_electricity])
- + end
- + end
- +end
- diff --git a/tmp/pids/server.pid b/tmp/pids/server.pid
- new file mode 100644
- index 0000000..c28a933
- --- /dev/null
- +++ b/tmp/pids/server.pid
- @@ -0,0 +1 @@
- +9576
- \ No newline at end of file
- --
- 2.15.0
Add Comment
Please, Sign In to add comment