Commit 3fd1304bf294ec6adb2ba24a8f419d7738be35d9
Committed by
Rafael Manzo
1 parent
153d6ef6
Exists in
colab
and in
4 other branches
WIP: Working on Reading acceptance tests.
Grade validation is wrong. We need to check whether the field was filled with letters.
Showing
8 changed files
with
25 additions
and
20 deletions
Show diff stats
app/controllers/readings_controller.rb
... | ... | @@ -9,6 +9,7 @@ class ReadingsController < ApplicationController |
9 | 9 | |
10 | 10 | def new |
11 | 11 | @reading = Reading.new |
12 | + @reading_group_id = params[:reading_group_id] | |
12 | 13 | end |
13 | 14 | |
14 | 15 | def create |
... | ... | @@ -55,7 +56,7 @@ class ReadingsController < ApplicationController |
55 | 56 | # Duplicated code on create and update actions extracted here |
56 | 57 | def failed_action(format, destiny_action) |
57 | 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 | 60 | end |
60 | 61 | |
61 | 62 | # Code extracted from create action |
... | ... | @@ -63,6 +64,7 @@ class ReadingsController < ApplicationController |
63 | 64 | if @reading.save |
64 | 65 | format.html { redirect_to reading_group_path(@reading.reading_group_id), notice: 'Reading was successfully created.' } |
65 | 66 | else |
67 | + @reading_group_id = params[:reading_group_id] | |
66 | 68 | failed_action(format, 'new') |
67 | 69 | end |
68 | 70 | end | ... | ... |
app/models/reading.rb
app/views/readings/_form.html.erb
... | ... | @@ -54,7 +54,13 @@ |
54 | 54 | |
55 | 55 | <div class="row margin-left-none" style="margin-top: 20px"> |
56 | 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 | 64 | </div> |
59 | 65 | |
60 | 66 | <script> | ... | ... |
app/views/readings/edit.html.erb
... | ... | @@ -2,6 +2,6 @@ |
2 | 2 | <h1>Editing Reading</h1> |
3 | 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 | 6 | <%= render partial: 'form', locals: {f: f} %> |
7 | 7 | <% end %> | ... | ... |
features/reading/edit.feature
... | ... | @@ -10,9 +10,9 @@ Feature: Reading Edit |
10 | 10 | And I own a sample reading group |
11 | 11 | And I have a sample reading within the sample reading group |
12 | 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 | 16 | When I fill the Label field with "Bad" |
17 | 17 | And I press the Save button |
18 | 18 | Then I should see "Bad" |
... | ... | @@ -25,7 +25,7 @@ Feature: Reading Edit |
25 | 25 | And I have a sample reading within the sample reading group |
26 | 26 | And I am at the Edit Reading page |
27 | 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 | 29 | And I fill the Color field with " " |
30 | 30 | And I press the Save button |
31 | 31 | Then I should see "Label can't be blank" |
... | ... | @@ -42,7 +42,7 @@ Feature: Reading Edit |
42 | 42 | And I am at the Edit Reading page |
43 | 43 | When I fill the Label field with "Average" |
44 | 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 | 47 | @kalibro_configuration_restart |
48 | 48 | Scenario: editing a reading with non numerical value | ... | ... |
features/reading/new.feature
... | ... | @@ -24,7 +24,7 @@ Feature: New reading |
24 | 24 | And I am at the New Reading page |
25 | 25 | And I fill the Label field with "My Reading" |
26 | 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 | 28 | When I press the Save button |
29 | 29 | Then I should be in the Sample Reading Group page |
30 | 30 | |
... | ... | @@ -59,9 +59,9 @@ Feature: New reading |
59 | 59 | And I am at the New Reading page |
60 | 60 | And I fill the Label field with "My Reading" |
61 | 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 | 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 | 65 | And I should be at the New Reading page |
66 | 66 | |
67 | 67 | @kalibro_configuration_restart |
... | ... | @@ -72,12 +72,12 @@ Feature: New reading |
72 | 72 | And I am at the New Reading page |
73 | 73 | And I fill the Label field with "My Reading" |
74 | 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 | 76 | When I press the Save button |
77 | 77 | Then I should see "Grade is not a number" |
78 | 78 | And I should be at the New Reading page |
79 | 79 | |
80 | - @kalibro_configuration_restart | |
80 | + @kalibro_configuration_restart @javascript | |
81 | 81 | Scenario: With an invalid color |
82 | 82 | Given I am a regular user |
83 | 83 | And I am signed in |
... | ... | @@ -87,5 +87,5 @@ Feature: New reading |
87 | 87 | And I fill the Grade field with "1" |
88 | 88 | And I fill the Color field with "z" |
89 | 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 | 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 "(.*?)"$/) do |name| |
12 | 12 | @reading_group = FactoryGirl.create(:reading_group, {name: name}) |
13 | 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 | 15 | Given(/^I own a sample reading group$/) do |
20 | 16 | @reading_group = FactoryGirl.create(:reading_group) |
21 | 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 | 2 | @reading = FactoryGirl.create(:reading, {reading_group_id: @reading_group.id}) |
3 | 3 | end |
4 | 4 | |
... | ... | @@ -7,7 +7,7 @@ Given(/^I am at the New Reading page$/) do |
7 | 7 | end |
8 | 8 | |
9 | 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 | 11 | end |
12 | 12 | |
13 | 13 | Given(/^I have a sample reading within the sample reading group labeled "(.*?)"$/) do |label| | ... | ... |