Commit c97f6bc648f55f3eb47bf53558d4ed643236bc89
1 parent
bce70a38
Exists in
colab
and in
4 other branches
Filtering projects by hidden
Showing
4 changed files
with
9 additions
and
2 deletions
Show diff stats
app/controllers/projects_controller.rb
| @@ -14,7 +14,10 @@ class ProjectsController < ApplicationController | @@ -14,7 +14,10 @@ class ProjectsController < ApplicationController | ||
| 14 | # GET /projects | 14 | # GET /projects |
| 15 | # GET /projects.json | 15 | # GET /projects.json |
| 16 | def index | 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 | end | 21 | end |
| 19 | 22 | ||
| 20 | # POST /projects | 23 | # POST /projects |
app/models/project.rb
| 1 | class Project < KalibroClient::Entities::Processor::Project | 1 | class Project < KalibroClient::Entities::Processor::Project |
| 2 | include KalibroRecord | 2 | include KalibroRecord |
| 3 | + | ||
| 3 | def self.latest(count = 1) | 4 | def self.latest(count = 1) |
| 4 | all.sort { |a,b| b.id <=> a.id }.select { |project| !project.attributes.hidden}.first(count) | 5 | all.sort { |a,b| b.id <=> a.id }.select { |project| !project.attributes.hidden}.first(count) |
| 5 | end | 6 | end |
app/views/projects/_form.html.erb
| @@ -17,7 +17,7 @@ | @@ -17,7 +17,7 @@ | ||
| 17 | <div class="form-row"> | 17 | <div class="form-row"> |
| 18 | <div class="field-container"> | 18 | <div class="field-container"> |
| 19 | <%= f.label "Image url", class: 'control-label' %><br> | 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 | </div> | 21 | </div> |
| 22 | </div> | 22 | </div> |
| 23 | </div> | 23 | </div> |
spec/controllers/projects_controller_spec.rb
| @@ -139,9 +139,12 @@ describe ProjectsController, :type => :controller do | @@ -139,9 +139,12 @@ describe ProjectsController, :type => :controller do | ||
| 139 | end | 139 | end |
| 140 | 140 | ||
| 141 | describe 'index' do | 141 | describe 'index' do |
| 142 | + let(:project_attributes) { FactoryGirl.build(:project_attributes) } | ||
| 143 | + | ||
| 142 | before :each do | 144 | before :each do |
| 143 | @subject = FactoryGirl.build(:project_with_id) | 145 | @subject = FactoryGirl.build(:project_with_id) |
| 144 | Project.expects(:all).returns([@subject]) | 146 | Project.expects(:all).returns([@subject]) |
| 147 | + @subject.expects(:attributes).returns(project_attributes) | ||
| 145 | get :index | 148 | get :index |
| 146 | end | 149 | end |
| 147 | 150 |