Commit 3fd1304bf294ec6adb2ba24a8f419d7738be35d9

Authored by Diego Camarinha
Committed by Rafael Manzo
1 parent 153d6ef6

WIP: Working on Reading acceptance tests.

Grade validation is wrong. We need to check whether the field was filled
with letters.
app/controllers/readings_controller.rb
@@ -9,6 +9,7 @@ class ReadingsController < ApplicationController @@ -9,6 +9,7 @@ class ReadingsController < ApplicationController
9 9
10 def new 10 def new
11 @reading = Reading.new 11 @reading = Reading.new
  12 + @reading_group_id = params[:reading_group_id]
12 end 13 end
13 14
14 def create 15 def create
@@ -55,7 +56,7 @@ class ReadingsController < ApplicationController @@ -55,7 +56,7 @@ class ReadingsController < ApplicationController
55 # Duplicated code on create and update actions extracted here 56 # Duplicated code on create and update actions extracted here
56 def failed_action(format, destiny_action) 57 def failed_action(format, destiny_action)
57 format.html { render action: destiny_action } 58 format.html { render action: destiny_action }
58 - format.json { render json: @reading.errors, status: :unprocessable_entity } 59 + format.json { render json: @reading.kalibro_errors, status: :unprocessable_entity }
59 end 60 end
60 61
61 # Code extracted from create action 62 # Code extracted from create action
@@ -63,6 +64,7 @@ class ReadingsController < ApplicationController @@ -63,6 +64,7 @@ class ReadingsController < ApplicationController
63 if @reading.save 64 if @reading.save
64 format.html { redirect_to reading_group_path(@reading.reading_group_id), notice: 'Reading was successfully created.' } 65 format.html { redirect_to reading_group_path(@reading.reading_group_id), notice: 'Reading was successfully created.' }
65 else 66 else
  67 + @reading_group_id = params[:reading_group_id]
66 failed_action(format, 'new') 68 failed_action(format, 'new')
67 end 69 end
68 end 70 end
app/models/reading.rb
1 class Reading < KalibroClient::Entities::Configurations::Reading 1 class Reading < KalibroClient::Entities::Configurations::Reading
  2 + include KalibroRecord
2 end 3 end
app/views/readings/_form.html.erb
@@ -54,7 +54,13 @@ @@ -54,7 +54,13 @@
54 54
55 <div class="row margin-left-none" style="margin-top: 20px"> 55 <div class="row margin-left-none" style="margin-top: 20px">
56 <%= f.submit 'Save', class: 'btn btn-primary' %> 56 <%= f.submit 'Save', class: 'btn btn-primary' %>
57 - <%= link_to 'Back', reading_group_path(@reading_group_id), class: 'btn btn-default' %> 57 + <% if @reading.persisted? %>
  58 + <%= f.hidden_field(:reading_group_id, value: @reading.reading_group_id) %>
  59 + <%= link_to 'Back', reading_group_path(@reading.reading_group_id), class: 'btn btn-default' %>
  60 + <% else %>
  61 + <%= f.hidden_field(:reading_group_id, value: @reading_group_id) %>
  62 + <%= link_to 'Back', reading_group_path(@reading_group_id), class: 'btn btn-default' %>
  63 + <% end %>
58 </div> 64 </div>
59 65
60 <script> 66 <script>
app/views/readings/edit.html.erb
@@ -2,6 +2,6 @@ @@ -2,6 +2,6 @@
2 <h1>Editing Reading</h1> 2 <h1>Editing Reading</h1>
3 </div> 3 </div>
4 4
5 -<%= form_for(@reading, :url => reading_group_reading_update_url(@reading_group_id, @reading.id), method: :put) do |f| %> 5 +<%= form_for(@reading, :url => reading_group_reading_update_path(@reading.reading_group_id, @reading.id), method: :put) do |f| %>
6 <%= render partial: 'form', locals: {f: f} %> 6 <%= render partial: 'form', locals: {f: f} %>
7 <% end %> 7 <% end %>
features/reading/edit.feature
@@ -10,9 +10,9 @@ Feature: Reading Edit @@ -10,9 +10,9 @@ Feature: Reading Edit
10 And I own a sample reading group 10 And I own a sample reading group
11 And I have a sample reading within the sample reading group 11 And I have a sample reading within the sample reading group
12 And I am at the Edit Reading page 12 And I am at the Edit Reading page
13 - Then the field "Label" should be filled with "Good"  
14 - And the field "Grade" should be filled with "10.5"  
15 - And the field "Color" should be filled with "33dd33" 13 + Then I fill the Label field with "Good"
  14 + And I fill the Grade field with "10.5"
  15 + And I fill the Color field with "33DD33"
16 When I fill the Label field with "Bad" 16 When I fill the Label field with "Bad"
17 And I press the Save button 17 And I press the Save button
18 Then I should see "Bad" 18 Then I should see "Bad"
@@ -25,7 +25,7 @@ Feature: Reading Edit @@ -25,7 +25,7 @@ Feature: Reading Edit
25 And I have a sample reading within the sample reading group 25 And I have a sample reading within the sample reading group
26 And I am at the Edit Reading page 26 And I am at the Edit Reading page
27 When I fill the Label field with " " 27 When I fill the Label field with " "
28 - And I fill the Grade field with " " 28 + And I fill the Grade field with " "
29 And I fill the Color field with " " 29 And I fill the Color field with " "
30 And I press the Save button 30 And I press the Save button
31 Then I should see "Label can't be blank" 31 Then I should see "Label can't be blank"
@@ -42,7 +42,7 @@ Feature: Reading Edit @@ -42,7 +42,7 @@ Feature: Reading Edit
42 And I am at the Edit Reading page 42 And I am at the Edit Reading page
43 When I fill the Label field with "Average" 43 When I fill the Label field with "Average"
44 And I press the Save button 44 And I press the Save button
45 - Then I should see "Label There is already a Reading with label Average! Please, choose another one." 45 + Then I should see "Label Should be unique within a Reading Group"
46 46
47 @kalibro_configuration_restart 47 @kalibro_configuration_restart
48 Scenario: editing a reading with non numerical value 48 Scenario: editing a reading with non numerical value
features/reading/new.feature
@@ -24,7 +24,7 @@ Feature: New reading @@ -24,7 +24,7 @@ Feature: New reading
24 And I am at the New Reading page 24 And I am at the New Reading page
25 And I fill the Label field with "My Reading" 25 And I fill the Label field with "My Reading"
26 And I fill the Grade field with "1" 26 And I fill the Grade field with "1"
27 - And I fill the Color field with "00000ff00" 27 + And I fill the Color field with "00ff00"
28 When I press the Save button 28 When I press the Save button
29 Then I should be in the Sample Reading Group page 29 Then I should be in the Sample Reading Group page
30 30
@@ -59,9 +59,9 @@ Feature: New reading @@ -59,9 +59,9 @@ Feature: New reading
59 And I am at the New Reading page 59 And I am at the New Reading page
60 And I fill the Label field with "My Reading" 60 And I fill the Label field with "My Reading"
61 And I fill the Grade field with "1" 61 And I fill the Grade field with "1"
62 - And I fill the Color field with "00000ff00" 62 + And I fill the Color field with "00ff00"
63 When I press the Save button 63 When I press the Save button
64 - Then I should see "1 error prohibited this Reading from being saved" 64 + Then I should see "Label Should be unique within a Reading Group"
65 And I should be at the New Reading page 65 And I should be at the New Reading page
66 66
67 @kalibro_configuration_restart 67 @kalibro_configuration_restart
@@ -72,12 +72,12 @@ Feature: New reading @@ -72,12 +72,12 @@ Feature: New reading
72 And I am at the New Reading page 72 And I am at the New Reading page
73 And I fill the Label field with "My Reading" 73 And I fill the Label field with "My Reading"
74 And I fill the Grade field with "z" 74 And I fill the Grade field with "z"
75 - And I fill the Color field with "00000ff00" 75 + And I fill the Color field with "000ff0"
76 When I press the Save button 76 When I press the Save button
77 Then I should see "Grade is not a number" 77 Then I should see "Grade is not a number"
78 And I should be at the New Reading page 78 And I should be at the New Reading page
79 79
80 - @kalibro_configuration_restart 80 + @kalibro_configuration_restart @javascript
81 Scenario: With an invalid color 81 Scenario: With an invalid color
82 Given I am a regular user 82 Given I am a regular user
83 And I am signed in 83 And I am signed in
@@ -87,5 +87,5 @@ Feature: New reading @@ -87,5 +87,5 @@ Feature: New reading
87 And I fill the Grade field with "1" 87 And I fill the Grade field with "1"
88 And I fill the Color field with "z" 88 And I fill the Color field with "z"
89 When I press the Save button 89 When I press the Save button
90 - Then I should see "1 error prohibited this Reading from being saved" 90 + Then I should see "Color must be hexadecimal"
91 And I should be at the New Reading page 91 And I should be at the New Reading page
features/step_definitions/reading_group_steps.rb
@@ -12,10 +12,6 @@ Given(/^I have a reading group named &quot;(.*?)&quot;$/) do |name| @@ -12,10 +12,6 @@ Given(/^I have a reading group named &quot;(.*?)&quot;$/) do |name|
12 @reading_group = FactoryGirl.create(:reading_group, {name: name}) 12 @reading_group = FactoryGirl.create(:reading_group, {name: name})
13 end 13 end
14 14
15 -Given(/^I have a sample reading within the sample reading group$/) do  
16 - @reading = FactoryGirl.create(:reading, {reading_group_id: @reading_group.id})  
17 -end  
18 -  
19 Given(/^I own a sample reading group$/) do 15 Given(/^I own a sample reading group$/) do
20 @reading_group = FactoryGirl.create(:reading_group) 16 @reading_group = FactoryGirl.create(:reading_group)
21 FactoryGirl.create(:reading_group_ownership, {user_id: @user.id, reading_group_id: @reading_group.id}) 17 FactoryGirl.create(:reading_group_ownership, {user_id: @user.id, reading_group_id: @reading_group.id})
features/step_definitions/reading_steps.rb
1 -Given(/^I have a sample reading within the module result$/) do 1 +Given(/^I have a sample reading within the sample reading group$/) do
2 @reading = FactoryGirl.create(:reading, {reading_group_id: @reading_group.id}) 2 @reading = FactoryGirl.create(:reading, {reading_group_id: @reading_group.id})
3 end 3 end
4 4
@@ -7,7 +7,7 @@ Given(/^I am at the New Reading page$/) do @@ -7,7 +7,7 @@ Given(/^I am at the New Reading page$/) do
7 end 7 end
8 8
9 Given(/^I am at the Edit Reading page$/) do 9 Given(/^I am at the Edit Reading page$/) do
10 - visit edit_reading_group_reading_url(@reading_group.id, @reading.id) 10 + visit edit_reading_group_reading_path(@reading_group.id, @reading.id)
11 end 11 end
12 12
13 Given(/^I have a sample reading within the sample reading group labeled "(.*?)"$/) do |label| 13 Given(/^I have a sample reading within the sample reading group labeled "(.*?)"$/) do |label|