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 6  
7 7 # GET /mezuro_configurations/new
8 8 def new
9   - @configuration = MezuroConfiguration.new
  9 + @mezuro_configuration = MezuroConfiguration.new
10 10 end
11 11  
12 12 # GET /mezuro_configurations
13 13 # GET /mezuro_configurations.json
14 14 def index
15   - @configurations = MezuroConfiguration.all
  15 + @mezuro_configurations = MezuroConfiguration.all
16 16 end
17 17  
18 18 # POST /mezuro_configurations
19 19 # POST /mezuro_configurations.json
20 20 def create
21   - @configuration = MezuroConfiguration.new(mezuro_configuration_params)
  21 + @mezuro_configuration = MezuroConfiguration.new(mezuro_configuration_params)
22 22 respond_to do |format|
23 23 create_and_redir(format)
24 24 end
... ... @@ -28,7 +28,7 @@ class MezuroConfigurationsController &lt; ApplicationController
28 28 # GET /mezuro_configurations/1.json
29 29 def show
30 30 set_mezuro_configuration
31   - @configuration_metric_configurations = @configuration.metric_configurations
  31 + @mezuro_configuration_metric_configurations = @mezuro_configuration.metric_configurations
32 32 end
33 33  
34 34 # GET /mezuro_configurations/1/edit
... ... @@ -40,8 +40,8 @@ class MezuroConfigurationsController &lt; ApplicationController
40 40  
41 41 def update
42 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 45 else
46 46 render "edit"
47 47 end
... ... @@ -51,8 +51,8 @@ class MezuroConfigurationsController &lt; ApplicationController
51 51 # DELETE /mezuro_configurations/1.json
52 52 def destroy
53 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 56 respond_to do |format|
57 57 format.html { redirect_to mezuro_configurations_url }
58 58 format.json { head :no_content }
... ... @@ -62,7 +62,7 @@ class MezuroConfigurationsController &lt; ApplicationController
62 62 private
63 63 # Use callbacks to share common setup or constraints between actions.
64 64 def set_mezuro_configuration
65   - @configuration = MezuroConfiguration.find(params[:id])
  65 + @mezuro_configuration = MezuroConfiguration.find(params[:id])
66 66 end
67 67  
68 68 # Never trust parameters from the scary internet, only allow the white list through.
... ... @@ -72,14 +72,14 @@ class MezuroConfigurationsController &lt; ApplicationController
72 72  
73 73 # Extracted code from create action
74 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 80 else
81 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 83 end
84 84 end
85 85 end
... ...
app/helpers/mezuro_configurations_helper.rb
1 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 4 end
5 5 end
6 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 4 <div class="form-group">
5 5 <%= f.label :name, class: 'control-label' %><br>
... ...
app/views/mezuro_configurations/_list.html.erb
... ... @@ -8,6 +8,6 @@
8 8 </thead>
9 9  
10 10 <tbody>
11   - <%= render @configurations %>
  11 + <%= render @mezuro_configurations %>
12 12 </tbody>
13 13 </table>
14 14 \ No newline at end of file
... ...
app/views/mezuro_configurations/_mezuro_configuration.html.erb
... ... @@ -3,7 +3,7 @@
3 3 <td><%= mezuro_configuration.description %></td>
4 4 <td><%= link_to 'Show', mezuro_configuration_path(mezuro_configuration.id), class: 'btn btn-info' %></td>
5 5 <td>
6   - <% if configuration_owner?(mezuro_configuration.id) %>
  6 + <% if mezuro_configuration_owner?(mezuro_configuration.id) %>
7 7 <%= link_to 'Edit', edit_mezuro_configuration_path(mezuro_configuration.id), class: 'btn btn-info' %>
8 8 <% end %>
9 9 </td>
... ...
app/views/mezuro_configurations/show.html.erb
1 1 <div class="page-header">
2   - <h1><%= @configuration.name %></h1>
  2 + <h1><%= @mezuro_configuration.name %></h1>
3 3 </div>
4 4  
5 5 <p>
6 6 <strong>Description:</strong>
7   - <%= @configuration.description %>
  7 + <%= @mezuro_configuration.description %>
8 8 </p>
9 9  
10 10 <hr>
11 11  
12 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 16 <% end %>
17 17  
18 18 <table class="table table-hover">
... ... @@ -23,13 +23,22 @@
23 23 <th>Weight</th>
24 24 </tr>
25 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 35 </table>
27 36  
28 37 <hr>
29 38  
30 39 <p>
31 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 43 <% end %>
35 44 </p>
... ...
features/metric_configuration/create.feature
... ... @@ -9,7 +9,7 @@ Feature: Metric Configuration Creation
9 9 And I am at the Sample Configuration page
10 10 Then I should not see New Metric Configuration
11 11  
12   - @kalibro_restart @wip
  12 + @kalibro_restart
13 13 Scenario: metric configuration creation
14 14 Given I am a regular user
15 15 And I am signed in
... ...
features/mezuro_configuration/deletion.feature
... ... @@ -23,6 +23,6 @@ Feature: Configuration Deletion
23 23 And I am signed in
24 24 And I own a sample configuration
25 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 27 Then I should be in the All configurations page
28   - And the sample configuration should not be there
29 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 7 Scenario: Checking configuration contents
8 8 Given I have a sample configuration
9 9 When I am at the Sample Configuration page
10 10 - Then the sample configuration should be there
  11 + Then the sample configuration should be there
11 12 \ No newline at end of file
... ...
features/reading/new.feature
... ... @@ -15,7 +15,7 @@ Feature: New reading
15 15 And I should see "Grade"
16 16 And I should see "Color"
17 17  
18   - @kalibro_restart @wip
  18 + @kalibro_restart
19 19 Scenario: With valid fields
20 20 Given I am a regular user
21 21 And I am signed in
... ...
spec/controllers/mezuro_configurations_controller_spec.rb
... ... @@ -164,8 +164,8 @@ describe MezuroConfigurationsController do
164 164  
165 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 169 end
170 170 end
171 171  
... ...
spec/helpers/mezuro_configurations_helper_spec.rb
1 1 require 'spec_helper'
2 2  
3 3 describe MezuroConfigurationsHelper do
4   - describe 'configuration_owner?' do
  4 + describe 'mezuro_configuration_owner?' do
5 5 before :each do
6 6 @subject = FactoryGirl.build(:mezuro_configuration)
7 7 end
... ... @@ -10,7 +10,7 @@ describe MezuroConfigurationsHelper do
10 10 before :each do
11 11 helper.expects(:user_signed_in?).returns(false)
12 12 end
13   - it { helper.configuration_owner?(@subject.id).should be_false }
  13 + it { helper.mezuro_configuration_owner?(@subject.id).should be_false }
14 14 end
15 15  
16 16 context 'returns false if is not the owner' do
... ... @@ -24,7 +24,7 @@ describe MezuroConfigurationsHelper do
24 24 User.any_instance.expects(:mezuro_configuration_ownerships).returns(@ownerships)
25 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 28 end
29 29  
30 30 context 'returns true if user is the mezuro_configuration owner' do
... ... @@ -38,7 +38,7 @@ describe MezuroConfigurationsHelper do
38 38 User.any_instance.expects(:mezuro_configuration_ownerships).returns(@ownerships)
39 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 42 end
43 43 end
44 44 end
45 45 \ No newline at end of file
... ...