Commit c97f6bc648f55f3eb47bf53558d4ed643236bc89

Authored by Heitor
1 parent bce70a38

Filtering projects by hidden

app/controllers/projects_controller.rb
... ... @@ -14,7 +14,10 @@ class ProjectsController < ApplicationController
14 14 # GET /projects
15 15 # GET /projects.json
16 16 def index
17   - @projects = Project.all
  17 + @projects = []
  18 + Project.all.each do |project|
  19 + @projects << project unless project.attributes.hidden? && current_user != project.attributes.user
  20 + end
18 21 end
19 22  
20 23 # POST /projects
... ...
app/models/project.rb
1 1 class Project < KalibroClient::Entities::Processor::Project
2 2 include KalibroRecord
  3 +
3 4 def self.latest(count = 1)
4 5 all.sort { |a,b| b.id <=> a.id }.select { |project| !project.attributes.hidden}.first(count)
5 6 end
... ...
app/views/projects/_form.html.erb
... ... @@ -17,7 +17,7 @@
17 17 <div class="form-row">
18 18 <div class="field-container">
19 19 <%= f.label "Image url", class: 'control-label' %><br>
20   - <%= f.text_field :image_url, class: 'text-area', value: @project.attributes.image_url.nil? ? '#' : @project.attributes.image_url %>
  20 + <%= f.text_field :image_url, class: 'text-area', value: @project.attributes.nil? || @project.attributes.image_url.nil? ? '#' : @project.attributes.image_url %>
21 21 </div>
22 22 </div>
23 23 </div>
... ...
spec/controllers/projects_controller_spec.rb
... ... @@ -139,9 +139,12 @@ describe ProjectsController, :type =&gt; :controller do
139 139 end
140 140  
141 141 describe 'index' do
  142 + let(:project_attributes) { FactoryGirl.build(:project_attributes) }
  143 +
142 144 before :each do
143 145 @subject = FactoryGirl.build(:project_with_id)
144 146 Project.expects(:all).returns([@subject])
  147 + @subject.expects(:attributes).returns(project_attributes)
145 148 get :index
146 149 end
147 150  
... ...