Commit f12fbe894dd9da6a4b3b6433d00b5459e7407a4c

Authored by Guilherme Rojas V. de Lima
Committed by Rafael Manzo
1 parent 9b94cafd

Refactored mezuro configuration

Renamed variables in view and controller.
Renamed the helper of mezuro configuration ownership.

signed-off-by: Fellipe Souto Sampaio <fllsouto@gmail.com>
app/controllers/mezuro_configurations_controller.rb
@@ -6,19 +6,19 @@ class MezuroConfigurationsController &lt; ApplicationController @@ -6,19 +6,19 @@ class MezuroConfigurationsController &lt; ApplicationController
6 6
7 # GET /mezuro_configurations/new 7 # GET /mezuro_configurations/new
8 def new 8 def new
9 - @configuration = MezuroConfiguration.new 9 + @mezuro_configuration = MezuroConfiguration.new
10 end 10 end
11 11
12 # GET /mezuro_configurations 12 # GET /mezuro_configurations
13 # GET /mezuro_configurations.json 13 # GET /mezuro_configurations.json
14 def index 14 def index
15 - @configurations = MezuroConfiguration.all 15 + @mezuro_configurations = MezuroConfiguration.all
16 end 16 end
17 17
18 # POST /mezuro_configurations 18 # POST /mezuro_configurations
19 # POST /mezuro_configurations.json 19 # POST /mezuro_configurations.json
20 def create 20 def create
21 - @configuration = MezuroConfiguration.new(mezuro_configuration_params) 21 + @mezuro_configuration = MezuroConfiguration.new(mezuro_configuration_params)
22 respond_to do |format| 22 respond_to do |format|
23 create_and_redir(format) 23 create_and_redir(format)
24 end 24 end
@@ -28,7 +28,7 @@ class MezuroConfigurationsController &lt; ApplicationController @@ -28,7 +28,7 @@ class MezuroConfigurationsController &lt; ApplicationController
28 # GET /mezuro_configurations/1.json 28 # GET /mezuro_configurations/1.json
29 def show 29 def show
30 set_mezuro_configuration 30 set_mezuro_configuration
31 - @configuration_metric_configurations = @configuration.metric_configurations 31 + @mezuro_configuration_metric_configurations = @mezuro_configuration.metric_configurations
32 end 32 end
33 33
34 # GET /mezuro_configurations/1/edit 34 # GET /mezuro_configurations/1/edit
@@ -40,8 +40,8 @@ class MezuroConfigurationsController &lt; ApplicationController @@ -40,8 +40,8 @@ class MezuroConfigurationsController &lt; ApplicationController
40 40
41 def update 41 def update
42 set_mezuro_configuration 42 set_mezuro_configuration
43 - if @configuration.update(mezuro_configuration_params)  
44 - redirect_to(mezuro_configuration_path(@configuration.id)) 43 + if @mezuro_configuration.update(mezuro_configuration_params)
  44 + redirect_to(mezuro_configuration_path(@mezuro_configuration.id))
45 else 45 else
46 render "edit" 46 render "edit"
47 end 47 end
@@ -51,8 +51,8 @@ class MezuroConfigurationsController &lt; ApplicationController @@ -51,8 +51,8 @@ class MezuroConfigurationsController &lt; ApplicationController
51 # DELETE /mezuro_configurations/1.json 51 # DELETE /mezuro_configurations/1.json
52 def destroy 52 def destroy
53 set_mezuro_configuration 53 set_mezuro_configuration
54 - current_user.mezuro_configuration_ownerships.find_by_mezuro_configuration_id(@configuration.id).destroy  
55 - @configuration.destroy 54 + current_user.mezuro_configuration_ownerships.find_by_mezuro_configuration_id(@mezuro_configuration.id).destroy
  55 + @mezuro_configuration.destroy
56 respond_to do |format| 56 respond_to do |format|
57 format.html { redirect_to mezuro_configurations_url } 57 format.html { redirect_to mezuro_configurations_url }
58 format.json { head :no_content } 58 format.json { head :no_content }
@@ -62,7 +62,7 @@ class MezuroConfigurationsController &lt; ApplicationController @@ -62,7 +62,7 @@ class MezuroConfigurationsController &lt; ApplicationController
62 private 62 private
63 # Use callbacks to share common setup or constraints between actions. 63 # Use callbacks to share common setup or constraints between actions.
64 def set_mezuro_configuration 64 def set_mezuro_configuration
65 - @configuration = MezuroConfiguration.find(params[:id]) 65 + @mezuro_configuration = MezuroConfiguration.find(params[:id])
66 end 66 end
67 67
68 # Never trust parameters from the scary internet, only allow the white list through. 68 # Never trust parameters from the scary internet, only allow the white list through.
@@ -72,14 +72,14 @@ class MezuroConfigurationsController &lt; ApplicationController @@ -72,14 +72,14 @@ class MezuroConfigurationsController &lt; ApplicationController
72 72
73 # Extracted code from create action 73 # Extracted code from create action
74 def create_and_redir(format) 74 def create_and_redir(format)
75 - if @configuration.save  
76 - current_user.mezuro_configuration_ownerships.create mezuro_configuration_id: @configuration.id 75 + if @mezuro_configuration.save
  76 + current_user.mezuro_configuration_ownerships.create mezuro_configuration_id: @mezuro_configuration.id
77 77
78 - format.html { redirect_to mezuro_configuration_path(@configuration.id), notice: 'mezuro_configuration was successfully created.' }  
79 - format.json { render action: 'show', status: :created, location: @configuration } 78 + format.html { redirect_to mezuro_configuration_path(@mezuro_configuration.id), notice: 'mezuro configuration was successfully created.' }
  79 + format.json { render action: 'show', status: :created, location: @mezuro_configuration }
80 else 80 else
81 format.html { render action: 'new' } 81 format.html { render action: 'new' }
82 - format.json { render json: @configuration.errors, status: :unprocessable_entity } 82 + format.json { render json: @mezuro_configuration.errors, status: :unprocessable_entity }
83 end 83 end
84 end 84 end
85 end 85 end
app/helpers/mezuro_configurations_helper.rb
1 module MezuroConfigurationsHelper 1 module MezuroConfigurationsHelper
2 - def configuration_owner?(configuration_id)  
3 - user_signed_in? && !current_user.mezuro_configuration_ownerships.find_by_mezuro_configuration_id(configuration_id).nil? 2 + def mezuro_configuration_owner?(mezuro_configuration_id)
  3 + user_signed_in? && !current_user.mezuro_configuration_ownerships.find_by_mezuro_configuration_id(mezuro_configuration_id).nil?
4 end 4 end
5 end 5 end
6 \ No newline at end of file 6 \ No newline at end of file
app/views/mezuro_configurations/_form.html.erb
1 -<%= form_for(@configuration, :html => { role: 'form' }) do |f| %>  
2 - <%= render :partial => 'shared/form_errors', :locals => {:object => @configuration} %> 1 +<%= form_for(@mezuro_configuration, :html => { role: 'form' }) do |f| %>
  2 + <%= render :partial => 'shared/form_errors', :locals => {:object => @mezuro_configuration} %>
3 3
4 <div class="form-group"> 4 <div class="form-group">
5 <%= f.label :name, class: 'control-label' %><br> 5 <%= f.label :name, class: 'control-label' %><br>
app/views/mezuro_configurations/_list.html.erb
@@ -8,6 +8,6 @@ @@ -8,6 +8,6 @@
8 </thead> 8 </thead>
9 9
10 <tbody> 10 <tbody>
11 - <%= render @configurations %> 11 + <%= render @mezuro_configurations %>
12 </tbody> 12 </tbody>
13 </table> 13 </table>
14 \ No newline at end of file 14 \ No newline at end of file
app/views/mezuro_configurations/_mezuro_configuration.html.erb
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 <td><%= mezuro_configuration.description %></td> 3 <td><%= mezuro_configuration.description %></td>
4 <td><%= link_to 'Show', mezuro_configuration_path(mezuro_configuration.id), class: 'btn btn-info' %></td> 4 <td><%= link_to 'Show', mezuro_configuration_path(mezuro_configuration.id), class: 'btn btn-info' %></td>
5 <td> 5 <td>
6 - <% if configuration_owner?(mezuro_configuration.id) %> 6 + <% if mezuro_configuration_owner?(mezuro_configuration.id) %>
7 <%= link_to 'Edit', edit_mezuro_configuration_path(mezuro_configuration.id), class: 'btn btn-info' %> 7 <%= link_to 'Edit', edit_mezuro_configuration_path(mezuro_configuration.id), class: 'btn btn-info' %>
8 <% end %> 8 <% end %>
9 </td> 9 </td>
app/views/mezuro_configurations/show.html.erb
1 <div class="page-header"> 1 <div class="page-header">
2 - <h1><%= @configuration.name %></h1> 2 + <h1><%= @mezuro_configuration.name %></h1>
3 </div> 3 </div>
4 4
5 <p> 5 <p>
6 <strong>Description:</strong> 6 <strong>Description:</strong>
7 - <%= @configuration.description %> 7 + <%= @mezuro_configuration.description %>
8 </p> 8 </p>
9 9
10 <hr> 10 <hr>
11 11
12 <h2> Metrics </h2> 12 <h2> Metrics </h2>
13 13
14 -<% if configuration_owner? @configuration.id %>  
15 - <%= link_to 'Add Metric', mezuro_configuration_choose_metric_path(@configuration), class: 'btn btn-info' %> 14 +<% if mezuro_configuration_owner? @mezuro_configuration.id %>
  15 + <%= link_to 'Add Metric', mezuro_configuration_choose_metric_path(@mezuro_configuration.id), class: 'btn btn-info' %>
16 <% end %> 16 <% end %>
17 17
18 <table class="table table-hover"> 18 <table class="table table-hover">
@@ -23,13 +23,22 @@ @@ -23,13 +23,22 @@
23 <th>Weight</th> 23 <th>Weight</th>
24 </tr> 24 </tr>
25 </thead> 25 </thead>
  26 + <tbody>
  27 + <% if @mezuro_configuration_metric_configurations.size == 0 %>
  28 + <%= render partial: 'no_metric_configurations' %>
  29 + <% else %>
  30 + <% cache do %>
  31 + <%= render partial: 'metric_configurations', collection: @mezuro_configuration_metric_configurations, as: :metric_configuration %>
  32 + <% end %>
  33 + <% end %>
  34 + </tbody>
26 </table> 35 </table>
27 36
28 <hr> 37 <hr>
29 38
30 <p> 39 <p>
31 <%= link_to 'Back', mezuro_configurations_path, class: 'btn btn-default' %> 40 <%= link_to 'Back', mezuro_configurations_path, class: 'btn btn-default' %>
32 - <% if configuration_owner? @configuration.id %>  
33 - <%= link_to 'Destroy Configuration', mezuro_configuration_path(@configuration.id), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' %> 41 + <% if mezuro_configuration_owner? @mezuro_configuration.id %>
  42 + <%= link_to 'Destroy Configuration', mezuro_configuration_path(@mezuro_configuration.id), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' %>
34 <% end %> 43 <% end %>
35 </p> 44 </p>
features/metric_configuration/create.feature
@@ -9,7 +9,7 @@ Feature: Metric Configuration Creation @@ -9,7 +9,7 @@ Feature: Metric Configuration Creation
9 And I am at the Sample Configuration page 9 And I am at the Sample Configuration page
10 Then I should not see New Metric Configuration 10 Then I should not see New Metric Configuration
11 11
12 - @kalibro_restart @wip 12 + @kalibro_restart
13 Scenario: metric configuration creation 13 Scenario: metric configuration creation
14 Given I am a regular user 14 Given I am a regular user
15 And I am signed in 15 And I am signed in
features/mezuro_configuration/deletion.feature
@@ -23,6 +23,6 @@ Feature: Configuration Deletion @@ -23,6 +23,6 @@ Feature: Configuration Deletion
23 And I am signed in 23 And I am signed in
24 And I own a sample configuration 24 And I own a sample configuration
25 And I am at the Sample Configuration page 25 And I am at the Sample Configuration page
26 - When I click the Destroy configuration link 26 + When I click the Destroy Configuration link
27 Then I should be in the All configurations page 27 Then I should be in the All configurations page
28 - And the sample configuration should not be there  
29 \ No newline at end of file 28 \ No newline at end of file
  29 + And the sample configuration should not be there
features/mezuro_configuration/show.feature
@@ -7,4 +7,4 @@ Feature: Show Configuration @@ -7,4 +7,4 @@ Feature: Show Configuration
7 Scenario: Checking configuration contents 7 Scenario: Checking configuration contents
8 Given I have a sample configuration 8 Given I have a sample configuration
9 When I am at the Sample Configuration page 9 When I am at the Sample Configuration page
10 - Then the sample configuration should be there 10 - Then the sample configuration should be there
  11 + Then the sample configuration should be there
11 \ No newline at end of file 12 \ No newline at end of file
features/reading/new.feature
@@ -15,7 +15,7 @@ Feature: New reading @@ -15,7 +15,7 @@ Feature: New reading
15 And I should see "Grade" 15 And I should see "Grade"
16 And I should see "Color" 16 And I should see "Color"
17 17
18 - @kalibro_restart @wip 18 + @kalibro_restart
19 Scenario: With valid fields 19 Scenario: With valid fields
20 Given I am a regular user 20 Given I am a regular user
21 And I am signed in 21 And I am signed in
spec/controllers/mezuro_configurations_controller_spec.rb
@@ -164,8 +164,8 @@ describe MezuroConfigurationsController do @@ -164,8 +164,8 @@ describe MezuroConfigurationsController do
164 164
165 it { should render_template(:edit) } 165 it { should render_template(:edit) }
166 166
167 - it 'should assign to @configuration the @subject' do  
168 - assigns(:configuration).should eq(@subject) 167 + it 'should assign to @mezuro_configuration the @subject' do
  168 + assigns(:mezuro_configuration).should eq(@subject)
169 end 169 end
170 end 170 end
171 171
spec/helpers/mezuro_configurations_helper_spec.rb
1 require 'spec_helper' 1 require 'spec_helper'
2 2
3 describe MezuroConfigurationsHelper do 3 describe MezuroConfigurationsHelper do
4 - describe 'configuration_owner?' do 4 + describe 'mezuro_configuration_owner?' do
5 before :each do 5 before :each do
6 @subject = FactoryGirl.build(:mezuro_configuration) 6 @subject = FactoryGirl.build(:mezuro_configuration)
7 end 7 end
@@ -10,7 +10,7 @@ describe MezuroConfigurationsHelper do @@ -10,7 +10,7 @@ describe MezuroConfigurationsHelper do
10 before :each do 10 before :each do
11 helper.expects(:user_signed_in?).returns(false) 11 helper.expects(:user_signed_in?).returns(false)
12 end 12 end
13 - it { helper.configuration_owner?(@subject.id).should be_false } 13 + it { helper.mezuro_configuration_owner?(@subject.id).should be_false }
14 end 14 end
15 15
16 context 'returns false if is not the owner' do 16 context 'returns false if is not the owner' do
@@ -24,7 +24,7 @@ describe MezuroConfigurationsHelper do @@ -24,7 +24,7 @@ describe MezuroConfigurationsHelper do
24 User.any_instance.expects(:mezuro_configuration_ownerships).returns(@ownerships) 24 User.any_instance.expects(:mezuro_configuration_ownerships).returns(@ownerships)
25 end 25 end
26 26
27 - it { helper.configuration_owner?(@subject.id).should be_false } 27 + it { helper.mezuro_configuration_owner?(@subject.id).should be_false }
28 end 28 end
29 29
30 context 'returns true if user is the mezuro_configuration owner' do 30 context 'returns true if user is the mezuro_configuration owner' do
@@ -38,7 +38,7 @@ describe MezuroConfigurationsHelper do @@ -38,7 +38,7 @@ describe MezuroConfigurationsHelper do
38 User.any_instance.expects(:mezuro_configuration_ownerships).returns(@ownerships) 38 User.any_instance.expects(:mezuro_configuration_ownerships).returns(@ownerships)
39 end 39 end
40 40
41 - it { helper.configuration_owner?(@subject.id).should be_true } 41 + it { helper.mezuro_configuration_owner?(@subject.id).should be_true }
42 end 42 end
43 end 43 end
44 end 44 end
45 \ No newline at end of file 45 \ No newline at end of file