Guest User

Untitled

a guest
Jun 24th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. From 5b20e0cbc500431fce7d5d19dc11290155b320f1 Mon Sep 17 00:00:00 2001
  2. From: Gregory Durelle <gdurelle@protonmail.com>
  3. Date: Sun, 24 Jun 2018 01:45:08 +0200
  4. Subject: [PATCH] My submission
  5. XOV: v1
  6.  
  7. add a gem for testing, add tests, fix typo, add request to return avg/min/max/etc
  8. ---
  9. Gemfile | 3 ++-
  10. Gemfile.lock | 5 +++++
  11. app/controllers/one_day_electricities_controller.rb | 5 +++++
  12. app/controllers/one_hour_electricities_controller.rb | 2 +-
  13. config/database.yml | 5 +++--
  14. .../one_day_electricities_controller_spec.rb | 18 ++++++++++++++++++
  15. .../one_hour_electricities_controller_spec.rb | 13 +++++++++++++
  16. tmp/pids/server.pid | 1 +
  17. 8 files changed, 48 insertions(+), 4 deletions(-)
  18. create mode 100644 spec/controllers/one_day_electricities_controller_spec.rb
  19. create mode 100644 spec/controllers/one_hour_electricities_controller_spec.rb
  20. create mode 100644 tmp/pids/server.pid
  21.  
  22. diff --git a/Gemfile b/Gemfile
  23. index ea2da3b..f494d1a 100755
  24. --- a/Gemfile
  25. +++ b/Gemfile
  26. @@ -17,4 +17,5 @@ group :test do
  27. gem 'factory_bot_rails'
  28. gem 'shoulda'
  29. gem 'simplecov', require: false
  30. -end
  31. \ No newline at end of file
  32. + gem 'rails-controller-testing'
  33. +end
  34. diff --git a/Gemfile.lock b/Gemfile.lock
  35. index 566cf14..71ed6b0 100755
  36. --- a/Gemfile.lock
  37. +++ b/Gemfile.lock
  38. @@ -92,6 +92,10 @@ GEM
  39. bundler (>= 1.3.0)
  40. railties (= 5.1.5)
  41. sprockets-rails (>= 2.0.0)
  42. + rails-controller-testing (1.0.2)
  43. + actionpack (~> 5.x, >= 5.0.1)
  44. + actionview (~> 5.x, >= 5.0.1)
  45. + activesupport (~> 5.x)
  46. rails-dom-testing (2.0.3)
  47. activesupport (>= 4.2.0)
  48. nokogiri (>= 1.6)
  49. @@ -160,6 +164,7 @@ DEPENDENCIES
  50. puma
  51. rack-cors
  52. rails (= 5.1.5)
  53. + rails-controller-testing
  54. rspec-rails (~> 3.7.2)
  55. shoulda
  56. simplecov
  57. diff --git a/app/controllers/one_day_electricities_controller.rb b/app/controllers/one_day_electricities_controller.rb
  58. index a48c2a0..646e969 100755
  59. --- a/app/controllers/one_day_electricities_controller.rb
  60. +++ b/app/controllers/one_day_electricities_controller.rb
  61. @@ -4,6 +4,11 @@ class OneDayElectricitiesController < ApplicationController
  62. # GET /one_day_electricities
  63. # GET /one_day_electricities.json
  64. def index
  65. + @one_day_electricities = OneHourElectricity.where(panel: @panel)
  66. + .where("DATE(hour) < ?", Date.today).select("DATE(hour) as day, SUM(kilowatts) as sum, \
  67. + MIN(kilowatts) as min, MAX(kilowatts) as max, \
  68. + AVG(kilowatts) as average").group("DATE(hour)")
  69. +
  70. end
  71.  
  72. private
  73. diff --git a/app/controllers/one_hour_electricities_controller.rb b/app/controllers/one_hour_electricities_controller.rb
  74. index b2178cc..5c3eef5 100755
  75. --- a/app/controllers/one_hour_electricities_controller.rb
  76. +++ b/app/controllers/one_hour_electricities_controller.rb
  77. @@ -28,7 +28,7 @@ class OneHourElectricitiesController < ApplicationController
  78. private
  79.  
  80. def set_panel
  81. - @panel = Panel.find_by_serial params[:banel_serial]
  82. + @panel = Panel.find_by_serial params[:panel_serial]
  83. end
  84.  
  85. # Whitelisting one-hour-electricity parameters
  86. diff --git a/config/database.yml b/config/database.yml
  87. index b9404c5..06a8242 100755
  88. --- a/config/database.yml
  89. +++ b/config/database.yml
  90. @@ -2,9 +2,10 @@ default: &default
  91. adapter: mysql2
  92. encoding: utf8
  93. username: root
  94. + password: r0OT_mysql
  95. host: localhost
  96. port: 3306
  97. - reconnect: false
  98. + # reconnect: false
  99. pool: 5
  100. timeout: 5000
  101.  
  102. @@ -21,4 +22,4 @@ test:
  103.  
  104. production:
  105. <<: *default
  106. - database: cross-solar-production
  107. \ No newline at end of file
  108. + database: cross-solar-production
  109. diff --git a/spec/controllers/one_day_electricities_controller_spec.rb b/spec/controllers/one_day_electricities_controller_spec.rb
  110. new file mode 100644
  111. index 0000000..419dbf0
  112. --- /dev/null
  113. +++ b/spec/controllers/one_day_electricities_controller_spec.rb
  114. @@ -0,0 +1,18 @@
  115. +require 'rails_helper'
  116. +
  117. +RSpec.describe OneDayElectricitiesController, type: :controller do
  118. + render_views
  119. +
  120. + describe "GET index" do
  121. + let!(:panel) { FactoryBot.create :panel }
  122. + it "assigns @panel" do
  123. + get :index, format: :json, params: { panel_serial: panel.serial }
  124. + expect(assigns(:panel)).to eq(panel)
  125. + end
  126. +
  127. + it "renders the index template" do
  128. + get :index, format: :json, params: { panel_serial: panel.serial }
  129. + expect(response).to render_template("index")
  130. + end
  131. + end
  132. +end
  133. diff --git a/spec/controllers/one_hour_electricities_controller_spec.rb b/spec/controllers/one_hour_electricities_controller_spec.rb
  134. new file mode 100644
  135. index 0000000..b3f819b
  136. --- /dev/null
  137. +++ b/spec/controllers/one_hour_electricities_controller_spec.rb
  138. @@ -0,0 +1,13 @@
  139. +require 'rails_helper'
  140. +
  141. +RSpec.describe OneHourElectricitiesController, type: :controller do
  142. + describe "GET index" do
  143. + let!(:one_hour_electricity) { FactoryBot.create :one_hour_electricity }
  144. + let(:panel) { one_hour_electricity.panel }
  145. + it "assigns @panel" do
  146. + get :index, format: :json, params: { panel_serial: panel.serial }
  147. + expect(assigns(:panel)).to eq(panel)
  148. + expect(assigns(:one_hour_electricities)).to eq([one_hour_electricity])
  149. + end
  150. + end
  151. +end
  152. diff --git a/tmp/pids/server.pid b/tmp/pids/server.pid
  153. new file mode 100644
  154. index 0000000..c28a933
  155. --- /dev/null
  156. +++ b/tmp/pids/server.pid
  157. @@ -0,0 +1 @@
  158. +9576
  159. \ No newline at end of file
  160. --
  161. 2.15.0
Add Comment
Please, Sign In to add comment