Commit 86904b59161f4fca1d02945127a4e656a7b6b668

Authored by Diego Camarinha
2 parents caaa5b13 75aafbfe

Merge pull request #183 from mezuro/hide_repositories

Hide repositories
app/controllers/concerns/ownership_authentication.rb
... ... @@ -52,7 +52,7 @@ module OwnershipAuthentication
52 52 private
53 53  
54 54 def check_project_ownership(id)
55   - if current_user.project_ownerships.find_by_project_id(id).nil?
  55 + if current_user.project_attributes.find_by_project_id(id).nil?
56 56 respond_to do |format|
57 57 format.html { redirect_to projects_url, notice: "You're not allowed to do this operation" }
58 58 format.json { head :no_content }
... ...
app/controllers/projects_controller.rb
... ... @@ -9,13 +9,12 @@ class ProjectsController < ApplicationController
9 9 # GET /projects/new
10 10 def new
11 11 @project = Project.new
12   - @project_image = ProjectImage.new
13 12 end
14 13  
15 14 # GET /projects
16 15 # GET /projects.json
17 16 def index
18   - @projects = Project.all
  17 + @projects = Project.all.select { |project| !project.attributes.hidden }
19 18 end
20 19  
21 20 # POST /projects
... ... @@ -25,7 +24,7 @@ class ProjectsController < ApplicationController
25 24 @project = Project.new(project_params)
26 25 respond_to do |format|
27 26 create_and_redir(format)
28   - ProjectImage.create(url: image_url, project_id: @project.id )
  27 + @project.attributes.update(image_url: image_url) unless @project.attributes.nil?
29 28 end
30 29 end
31 30  
... ... @@ -45,7 +44,7 @@ class ProjectsController < ApplicationController
45 44 def update
46 45 set_project
47 46 image_url = project_params.delete(:image_url)
48   - if @project.update(project_params) && @project_image.update(url: image_url)
  47 + if @project.update(project_params) && @project.attributes.update(image_url: image_url)
49 48 redirect_to(project_path(@project.id))
50 49 else
51 50 render "edit"
... ... @@ -56,7 +55,7 @@ class ProjectsController < ApplicationController
56 55 # DELETE /project/1.json
57 56 def destroy
58 57 set_project
59   - current_user.project_ownerships.find_by_project_id(@project.id).destroy
  58 + current_user.project_attributes.find_by_project_id(@project.id).destroy
60 59 @project.destroy
61 60 respond_to do |format|
62 61 format.html { redirect_to projects_url }
... ... @@ -68,7 +67,6 @@ class ProjectsController < ApplicationController
68 67 # Use callbacks to share common setup or constraints between actions.
69 68 def set_project
70 69 @project = find_resource(Project, params[:id].to_i)
71   - @project_image = ProjectImage.find_by_project_id(@project.id) if @project.is_a?(Project)
72 70 end
73 71  
74 72 # Never trust parameters from the scary internet, only allow the white list through.
... ... @@ -80,7 +78,7 @@ class ProjectsController < ApplicationController
80 78 # Extracted code from create action
81 79 def create_and_redir(format)
82 80 if @project.save
83   - current_user.project_ownerships.create project_id: @project.id
  81 + current_user.project_attributes.create(project_id: @project.id)
84 82 format.html { redirect_to project_path(@project.id), notice: 'Project was successfully created.' }
85 83 format.json { render action: 'show', status: :created, location: @project }
86 84 else
... ...
app/helpers/projects_helper.rb
1 1 module ProjectsHelper
2 2 def project_owner? project_id
3   - user_signed_in? && !current_user.project_ownerships.find_by_project_id(project_id).nil?
  3 + user_signed_in? && !current_user.project_attributes.find_by_project_id(project_id).nil?
4 4 end
5 5 end
6 6 \ No newline at end of file
... ...
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   - all.sort { |a,b| b.id <=> a.id }.first(count)
  5 + all.sort { |a,b| b.id <=> a.id }.select { |project| !project.attributes.hidden}.first(count)
  6 + end
  7 +
  8 + def attributes
  9 + project_attributes = ProjectAttributes.find_by_project_id(self.id)
  10 + project_attributes.nil? ? ProjectAttributes.new : project_attributes
5 11 end
6 12 end
... ...
app/models/project_attributes.rb 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +class ProjectAttributes < ActiveRecord::Base
  2 + belongs_to :user
  3 + belongs_to :project
  4 +
  5 + def project
  6 + Project.find(self.project_id)
  7 + end
  8 +end
... ...
app/models/project_image.rb
  1 +#FIXME: remove this after the migration has been done and modify the migration accordingly
1 2 class ProjectImage < ActiveRecord::Base
2 3 belongs_to :project
3 4 end
... ...
app/models/project_ownership.rb
  1 +#FIXME: remove this after the migration has been done and modify the migration accordingly
1 2 class ProjectOwnership < ActiveRecord::Base
2 3 belongs_to :user
3 4 validates :project_id, presence: true
... ...
app/models/user.rb
... ... @@ -8,12 +8,12 @@ class User &lt; ActiveRecord::Base
8 8 validates :email, presence: true
9 9 validates :email, uniqueness: true
10 10  
11   - has_many :project_ownerships
  11 + has_many :project_attributes, class_name: 'ProjectAttributes'
12 12 has_many :reading_group_ownerships
13 13 has_many :kalibro_configuration_ownerships
14 14 # Alert: when adding new parameters to this model, they should also be added to registrations_controller
15 15  
16 16 def projects
17   - project_ownerships.map { |project_ownership| project_ownership.project }
  17 + project_attributes.map { |project_attr| project_attr.project }
18 18 end
19 19 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_image.nil? ? '#' : @project_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>
... ...
db/migrate/20150225170704_create_project_attributes.rb 0 → 100644
... ... @@ -0,0 +1,56 @@
  1 +class CreateProjectAttributes < ActiveRecord::Migration
  2 + def up
  3 + create_table :project_attributes do |t|
  4 + t.integer :project_id
  5 + t.string :image_url
  6 + t.integer :user_id
  7 + t.boolean :hidden, default: false
  8 +
  9 + t.timestamps null: false
  10 + end
  11 +
  12 + ProjectOwnership.all.each do |project_ownership|
  13 + project_image = ProjectImage.find_by_project_id(project_ownership.project_id)
  14 + image_url = project_image.nil? ? "": project_image.url
  15 +
  16 + begin
  17 + # We want to hides projects prior this date since they probably have a invalid configuration
  18 + if Project.find(project_ownership.project_id).updated_at < DateTime.parse("Mon, 23 Feb 2015")
  19 + hidden = true
  20 + else
  21 + hidden = false
  22 + end
  23 +
  24 + ProjectAttributes.create(user_id: project_ownership.user_id, project_id: project_ownership.project_id, image_url: image_url, hidden: hidden)
  25 + rescue KalibroClient::Errors::RecordNotFound
  26 + puts "Could not find project with id #{project_ownership.project_id} owned by user with #{project_ownership.user_id} and image url #{image_url}"
  27 + end
  28 + end
  29 +
  30 + drop_table :project_ownerships
  31 + drop_table :project_images
  32 + end
  33 +
  34 + def down
  35 + create_table :project_ownerships do |t|
  36 + t.integer :user_id
  37 + t.integer :project_id
  38 +
  39 + t.timestamps
  40 + end
  41 +
  42 + create_table :project_images do |t|
  43 + t.belongs_to :project
  44 + t.string :url
  45 +
  46 + t.timestamps
  47 + end
  48 +
  49 + ProjectAttributes.all.each do |project_attribute|
  50 + ProjectOwnership.create(user_id: project_attribute.user_id, project_id: project_attribute.project_id)
  51 + ProjectImage.create(url: project_attribute.image_url, project_id: project_attribute.project_id)
  52 + end
  53 +
  54 + drop_table :project_attributes
  55 + end
  56 +end
... ...
db/schema.rb
... ... @@ -11,7 +11,7 @@
11 11 #
12 12 # It's strongly recommended that you check this file into your version control system.
13 13  
14   -ActiveRecord::Schema.define(version: 20141211114023) do
  14 +ActiveRecord::Schema.define(version: 20150225170704) do
15 15  
16 16 create_table "kalibro_configuration_ownerships", force: :cascade do |t|
17 17 t.integer "user_id"
... ... @@ -20,18 +20,13 @@ ActiveRecord::Schema.define(version: 20141211114023) do
20 20 t.datetime "updated_at"
21 21 end
22 22  
23   - create_table "project_images", force: :cascade do |t|
  23 + create_table "project_attributes", force: :cascade do |t|
24 24 t.integer "project_id"
25   - t.string "url", limit: 255
26   - t.datetime "created_at"
27   - t.datetime "updated_at"
28   - end
29   -
30   - create_table "project_ownerships", force: :cascade do |t|
  25 + t.string "image_url"
31 26 t.integer "user_id"
32   - t.integer "project_id"
33   - t.datetime "created_at"
34   - t.datetime "updated_at"
  27 + t.boolean "hidden", default: false
  28 + t.datetime "created_at", null: false
  29 + t.datetime "updated_at", null: false
35 30 end
36 31  
37 32 create_table "reading_group_ownerships", force: :cascade do |t|
... ...
features/project/deletion.feature
... ... @@ -22,7 +22,7 @@ Feature: Project Deletion
22 22 Given I am a regular user
23 23 And I am signed in
24 24 And I own a sample project
25   - And I have a sample project_image
  25 + And I have sample project_attributes
26 26 And I am at the Sample Project page
27 27 When I click the Destroy Project link
28 28 Then I should be in the All Projects page
... ...
features/project/edition.feature
... ... @@ -8,7 +8,7 @@ Feature: Project
8 8 Given I am a regular user
9 9 And I am signed in
10 10 And I own a sample project
11   - And I have a sample project_image
  11 + And I have sample project_attributes
12 12 And I am at the All Projects page
13 13 When I click the Edit link
14 14 Then I should be in the Edit Project page
... ... @@ -35,7 +35,7 @@ Feature: Project
35 35 Given I am a regular user
36 36 And I am signed in
37 37 And I own a sample project
38   - And I have a sample project_image
  38 + And I have sample project_attributes
39 39 And I am at the All Projects page
40 40 When I click the Edit link
41 41 Then The field "project[name]" should be filled with the sample project "name"
... ... @@ -46,7 +46,7 @@ Feature: Project
46 46 Given I am a regular user
47 47 And I am signed in
48 48 And I own a sample project
49   - And I have a sample project_image
  49 + And I have sample project_attributes
50 50 And I am at the sample project edit page
51 51 And I fill the Name field with "Kalibro"
52 52 And I fill the Description field with "Web Service to collect metrics"
... ... @@ -61,7 +61,7 @@ Feature: Project
61 61 And I have a project named "Qt-Calculator"
62 62 And I own a project named "Kalibro"
63 63 And I am at the sample project edit page
64   - And I have a sample project_image
  64 + And I have sample project_attributes
65 65 And I fill the Name field with "Qt-Calculator"
66 66 When I press the Save button
67 67 Then I should see "Name has already been taken"
... ... @@ -71,7 +71,7 @@ Feature: Project
71 71 Given I am a regular user
72 72 And I am signed in
73 73 And I own a sample project
74   - And I have a sample project_image
  74 + And I have sample project_attributes
75 75 And I am at the sample project edit page
76 76 And I fill the Description field with "Web Service to collect metrics"
77 77 When I press the Save button
... ... @@ -82,7 +82,7 @@ Feature: Project
82 82 Given I am a regular user
83 83 And I am signed in
84 84 And I own a sample project
85   - And I have a sample project_image
  85 + And I have sample project_attributes
86 86 And I am at the sample project edit page
87 87 And I fill the Name field with " "
88 88 When I press the Save button
... ...
features/project/listing.feature
... ... @@ -25,7 +25,7 @@ Feature: Project listing
25 25 Given I am a regular user
26 26 And I am signed in
27 27 And I have a sample project
28   - And I have a sample project_image
  28 + And I have sample project_attributes
29 29 And I am at the All Projects page
30 30 When I click the Show link
31 31 Then the sample project should be there
32 32 \ No newline at end of file
... ...
features/project/show.feature
... ... @@ -7,7 +7,7 @@ Feature: Show Project
7 7 Scenario: Should not show the create repository link to user that doesn't own the project
8 8 Given I am a regular user
9 9 And I have a sample project
10   - And I have a sample project_image
  10 + And I have sample project_attributes
11 11 And I have a sample configuration with native metrics
12 12 And I have a sample repository within the sample project
13 13 When I am at the Sample Project page
... ... @@ -20,7 +20,7 @@ Scenario: Should show the create repository link the project owner
20 20 Given I am a regular user
21 21 And I am signed in
22 22 And I own a sample project
23   - And I have a sample project_image
  23 + And I have sample project_attributes
24 24 When I am at the Sample Project page
25 25 Then I should see "New Repository"
26 26  
... ... @@ -28,7 +28,7 @@ Scenario: Should show the create repository link the project owner
28 28 @kalibro_processor_restart
29 29 Scenario: Considering the project has no repositories
30 30 Given I have a sample project
31   - And I have a sample project_image
  31 + And I have sample project_attributes
32 32 When I am at the Sample Project page
33 33 Then I should see "There are no Repositories yet!"
34 34  
... ... @@ -43,6 +43,6 @@ Scenario: Considering the project has repositories
43 43 @kalibro_processor_restart
44 44 Scenario: Checking project contents
45 45 Given I have a sample project
46   - And I have a sample project_image
  46 + And I have sample project_attributes
47 47 When I am at the Sample Project page
48 48 Then the sample project should be there
... ...
features/step_definitions/project_steps.rb
... ... @@ -8,8 +8,8 @@ Given(/^I have a sample project$/) do
8 8 @project = FactoryGirl.create(:project)
9 9 end
10 10  
11   -Given(/^I have a sample project_image$/) do
12   - @project_image = FactoryGirl.create(:project_image, {id: nil})
  11 +Given(/^I have sample project_attributes$/) do
  12 + @project_attributes = FactoryGirl.create(:project_attributes, {id: nil})
13 13 end
14 14  
15 15 Given(/^I have a project named "(.*?)"$/) do |name|
... ... @@ -18,12 +18,12 @@ end
18 18  
19 19 Given(/^I own a sample project$/) do
20 20 @project = FactoryGirl.create(:project)
21   - FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @project.id})
  21 + FactoryGirl.create(:project_attributes, {user_id: @user.id, project_id: @project.id})
22 22 end
23 23  
24 24 Given(/^I own a project named "(.*?)"$/) do |name|
25 25 @project = FactoryGirl.create(:project, {name: name})
26   - FactoryGirl.create(:project_ownership, {user_id: @user.id, project_id: @project.id})
  26 + FactoryGirl.create(:project_attributes, {user_id: @user.id, project_id: @project.id})
27 27 end
28 28  
29 29 Given(/^I am at the Sample Project page$/) do
... ...
spec/controllers/concerns/ownership_authentication_spec.rb
... ... @@ -111,12 +111,12 @@ describe OwnershipAuthentication, type: :controller do
111 111 end
112 112  
113 113 context 'when the user owns the Repository' do
114   - let!(:project_ownership) { FactoryGirl.build(:project_ownership, {user_id: current_user.id, project_id: project.id}) }
  114 + let!(:project_attributes) { FactoryGirl.build(:project_attributes, {user_id: current_user.id, project_id: project.id}) }
115 115  
116 116 before do
117   - project_ownerships = Object.new
118   - project_ownerships.expects(:find_by_project_id).with(project.id).returns(project_ownership)
119   - current_user.expects(:project_ownerships).returns(project_ownerships)
  117 + project_attrs = Object.new
  118 + project_attrs.expects(:find_by_project_id).with(project.id).returns(project_attributes)
  119 + current_user.expects(:project_attributes).returns(project_attrs)
120 120 end
121 121  
122 122 it 'should return true' do
... ... @@ -126,9 +126,9 @@ describe OwnershipAuthentication, type: :controller do
126 126  
127 127 context 'when the user does not own the Repository' do
128 128 before do
129   - project_ownerships = Object.new
130   - project_ownerships.expects(:find_by_project_id).with(project.id).returns(nil)
131   - current_user.expects(:project_ownerships).returns(project_ownerships)
  129 + project_attrs = Object.new
  130 + project_attrs.expects(:find_by_project_id).with(project.id).returns(nil)
  131 + current_user.expects(:project_attributes).returns(project_attrs)
132 132 end
133 133  
134 134 it 'should respond' do # FIXME: this is not the best test, but it it's the closest we can do I think
... ...
spec/controllers/projects_controller_spec.rb
... ... @@ -91,21 +91,20 @@ describe ProjectsController, :type =&gt; :controller do
91 91 context 'with a User logged in' do
92 92 before do
93 93 sign_in FactoryGirl.create(:user)
94   - @ownership = FactoryGirl.build(:project_ownership)
95   - @ownerships = []
96   -
  94 + @project_attributes = FactoryGirl.build(:project_attributes)
  95 + @attributes = []
97 96 end
98 97  
99 98 context 'when the user owns the project' do
100 99 before :each do
101   - @ownership.expects(:destroy)
  100 + @project_attributes.expects(:destroy)
102 101 @subject.expects(:destroy)
103 102  
104 103 #Those two mocks looks the same but they are necessary since params[:id] is a String and @project.id is an Integer :(
105   - @ownerships.expects(:find_by_project_id).with("#{@subject.id}").returns(@ownership)
106   - @ownerships.expects(:find_by_project_id).with(@subject.id).returns(@ownership)
  104 + @attributes.expects(:find_by_project_id).with("#{@subject.id}").returns(@project_attributes)
  105 + @attributes.expects(:find_by_project_id).with(@subject.id).returns(@project_attributes)
107 106  
108   - User.any_instance.expects(:project_ownerships).at_least_once.returns(@ownerships)
  107 + User.any_instance.expects(:project_attributes).at_least_once.returns(@attributes)
109 108  
110 109 subject.expects(:find_resource).with(Project, @subject.id).returns(@subject)
111 110 delete :destroy, :id => @subject.id
... ... @@ -120,8 +119,8 @@ describe ProjectsController, :type =&gt; :controller do
120 119  
121 120 context "when the user doesn't own the project" do
122 121 before :each do
123   - @ownerships.expects(:find_by_project_id).with("#{@subject.id}").returns(nil)
124   - User.any_instance.expects(:project_ownerships).at_least_once.returns(@ownerships)
  122 + @attributes.expects(:find_by_project_id).with("#{@subject.id}").returns(nil)
  123 + User.any_instance.expects(:project_attributes).at_least_once.returns(@attributes)
125 124  
126 125 delete :destroy, :id => @subject.id
127 126 end
... ... @@ -140,9 +139,12 @@ describe ProjectsController, :type =&gt; :controller do
140 139 end
141 140  
142 141 describe 'index' do
  142 + let(:project_attributes) { FactoryGirl.build(:project_attributes) }
  143 +
143 144 before :each do
144 145 @subject = FactoryGirl.build(:project_with_id)
145 146 Project.expects(:all).returns([@subject])
  147 + @subject.expects(:attributes).returns(project_attributes)
146 148 get :index
147 149 end
148 150  
... ... @@ -152,15 +154,14 @@ describe ProjectsController, :type =&gt; :controller do
152 154 describe 'edit' do
153 155 before do
154 156 @subject = FactoryGirl.build(:project_with_id)
155   - @project_image = FactoryGirl.create(:project_image)
156 157 end
157 158  
158 159 context 'with an User logged in' do
159 160 before do
160 161 @user = FactoryGirl.create(:user)
161   - @ownership = FactoryGirl.build(:project_ownership)
162   - @ownerships = []
163   - User.any_instance.expects(:project_ownerships).at_least_once.returns(@ownerships)
  162 + @attribute = FactoryGirl.build(:project_attributes)
  163 + @attributes = []
  164 + User.any_instance.expects(:project_attributes).at_least_once.returns(@attributes)
164 165  
165 166 sign_in @user
166 167 end
... ... @@ -168,8 +169,7 @@ describe ProjectsController, :type =&gt; :controller do
168 169 context 'when the user owns the project' do
169 170 before :each do
170 171 subject.expects(:find_resource).with(Project, @subject.id).returns(@subject)
171   - @ownerships.expects(:find_by_project_id).with("#{@subject.id}").returns(@ownership)
172   - ProjectImage.expects(:find_by_project_id).with(@subject.id).returns(@project_image)
  172 + @attributes.expects(:find_by_project_id).with("#{@subject.id}").returns(@attribute)
173 173  
174 174 get :edit, :id => @subject.id
175 175 end
... ... @@ -184,7 +184,7 @@ describe ProjectsController, :type =&gt; :controller do
184 184 context 'when the user does not own the project' do
185 185 before do
186 186 @subject = FactoryGirl.build(:another_project)
187   - @ownerships.expects(:find_by_project_id).with("#{@subject.id}").returns(nil)
  187 + @attributes.expects(:find_by_project_id).with("#{@subject.id}").returns(nil)
188 188  
189 189 get :edit, :id => @subject.id
190 190 end
... ... @@ -205,7 +205,6 @@ describe ProjectsController, :type =&gt; :controller do
205 205  
206 206 describe 'update' do
207 207 before do
208   - @project_image = FactoryGirl.build(:project_image)
209 208 @subject = FactoryGirl.build(:project_with_id)
210 209 @subject_params = @subject.to_hash
211 210 end
... ... @@ -217,17 +216,18 @@ describe ProjectsController, :type =&gt; :controller do
217 216  
218 217 context 'when user owns the project' do
219 218 before do
220   - @ownership = FactoryGirl.build(:project_ownership)
221   - @ownerships = []
222   - @ownerships.expects(:find_by_project_id).with("#{@subject.id}").returns(@ownership)
223   - User.any_instance.expects(:project_ownerships).at_least_once.returns(@ownerships)
224   - ProjectImage.expects(:find_by_project_id).with(@subject.id).returns(@project_image)
  219 + @project_attributes = FactoryGirl.build(:project_attributes)
  220 + @attributes = []
  221 + @attributes.expects(:find_by_project_id).with("#{@subject.id}").returns(@project_attributes)
  222 + User.any_instance.expects(:project_attributes).at_least_once.returns(@attributes)
225 223 end
226 224  
227 225 context 'with valid fields' do
228 226 before :each do
229 227 subject.expects(:find_resource).with(Project, @subject.id).returns(@subject)
230 228 Project.any_instance.expects(:update).with(@subject_params).returns(true)
  229 + @project_attributes.expects(:update).with(image_url: @subject_params[:image_url]).returns(true)
  230 + @subject.expects(:attributes).returns(@project_attributes)
231 231 end
232 232  
233 233 context 'rendering the show' do
... ...
spec/factories/project_attributes.rb 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +FactoryGirl.define do
  2 + factory :project_attributes, :class => 'ProjectAttributes' do
  3 + project_id 1
  4 + image_url "MyString"
  5 + user_id 1
  6 + hidden false
  7 + end
  8 +end
... ...
spec/factories/project_images.rb
... ... @@ -1,12 +0,0 @@
1   -# Read about factories at https://github.com/thoughtbot/factory_girl
2   -
3   -FactoryGirl.define do
4   - factory :project_image do
5   - project_id 1
6   - url "logo.png"
7   - end
8   -
9   - factory :project_no_image, class: ProjectImage do
10   - url nil
11   - end
12   -end
spec/factories/project_ownerships.rb
... ... @@ -1,8 +0,0 @@
1   -# Read about factories at https://github.com/thoughtbot/factory_girl
2   -
3   -FactoryGirl.define do
4   - factory :project_ownership do
5   - user_id 1
6   - project_id 1
7   - end
8   -end
spec/helpers/projects_helper_spec.rb
... ... @@ -19,10 +19,10 @@ describe ProjectsHelper, :type =&gt; :helper do
19 19 helper.expects(:user_signed_in?).returns(true)
20 20 helper.expects(:current_user).returns(FactoryGirl.build(:user))
21 21  
22   - @ownerships = []
23   - @ownerships.expects(:find_by_project_id).with(@subject.id).returns(nil)
  22 + @attributes = []
  23 + @attributes.expects(:find_by_project_id).with(@subject.id).returns(nil)
24 24  
25   - User.any_instance.expects(:project_ownerships).returns(@ownerships)
  25 + User.any_instance.expects(:project_attributes).returns(@attributes)
26 26 end
27 27  
28 28 it { expect(helper.project_owner?(@subject.id)).to be_falsey }
... ... @@ -33,10 +33,10 @@ describe ProjectsHelper, :type =&gt; :helper do
33 33 helper.expects(:user_signed_in?).returns(true)
34 34 helper.expects(:current_user).returns(FactoryGirl.build(:user))
35 35  
36   - @ownership = FactoryGirl.build(:project_ownership)
37   - @ownerships = []
38   - @ownerships.expects(:find_by_project_id).with(@subject.id).returns(@ownership)
39   - User.any_instance.expects(:project_ownerships).returns(@ownerships)
  36 + @project_attributes = FactoryGirl.build(:project_attributes)
  37 + @attributes = []
  38 + @attributes.expects(:find_by_project_id).with(@subject.id).returns(@project_attributes)
  39 + User.any_instance.expects(:project_attributes).returns(@attributes)
40 40 end
41 41  
42 42 it { expect(helper.project_owner?(@subject.id)).to be_truthy }
... ...
spec/models/project_attributes_spec.rb 0 → 100644
... ... @@ -0,0 +1,23 @@
  1 +require 'rails_helper'
  2 +
  3 +RSpec.describe ProjectAttributes, type: :model do
  4 + describe 'associations' do
  5 + it { is_expected.to belong_to(:user) }
  6 + it { is_expected.to belong_to(:project) }
  7 + end
  8 +
  9 + describe 'methods' do
  10 + describe 'project' do
  11 + subject { FactoryGirl.build(:project_attributes) }
  12 + let(:project) {FactoryGirl.build(:project_with_id)}
  13 +
  14 + before :each do
  15 + Project.expects(:find).with(subject.project_id).returns(project)
  16 + end
  17 +
  18 + it 'should return the project' do
  19 + expect(subject.project).to eq(project)
  20 + end
  21 + end
  22 + end
  23 +end
... ...
spec/models/project_image_spec.rb
... ... @@ -1,7 +0,0 @@
1   -require 'rails_helper'
2   -
3   -RSpec.describe ProjectImage, :type => :model do
4   - describe 'associations' do
5   - it { is_expected.to belong_to(:project) }
6   - end
7   -end
spec/models/project_ownership_spec.rb
... ... @@ -1,22 +0,0 @@
1   -require 'rails_helper'
2   -
3   -describe ProjectOwnership, :type => :model do
4   - describe 'associations' do
5   - it { is_expected.to belong_to(:user) }
6   - end
7   -
8   - describe 'methods' do
9   - describe 'project' do
10   - subject {FactoryGirl.build(:project_ownership)}
11   - let(:project) {FactoryGirl.build(:project_with_id)}
12   -
13   - before :each do
14   - Project.expects(:find).with(subject.project_id).returns(project)
15   - end
16   -
17   - it 'should return the project' do
18   - expect(subject.project).to eq(project)
19   - end
20   - end
21   - end
22   -end
spec/models/project_spec.rb
... ... @@ -3,22 +3,40 @@ require &#39;rails_helper&#39;
3 3 describe Project, :type => :model do
4 4 describe 'methods' do
5 5 describe 'latest' do
  6 + let!(:project) { FactoryGirl.build(:project_with_id, id: 1) }
  7 + let!(:another_project) { FactoryGirl.build(:another_project, id: 2) }
  8 + let!(:project_attributes) { FactoryGirl.build(:project_attributes) }
  9 +
6 10 before :each do
7   - @qt = FactoryGirl.build(:project_with_id)
8   - @kalibro = FactoryGirl.build(:another_project)
  11 + project.expects(:attributes).returns(project_attributes)
  12 + another_project.expects(:attributes).returns(project_attributes)
9 13  
10   - Project.expects(:all).returns([@qt, @kalibro])
  14 + Project.expects(:all).returns([project, another_project])
11 15 end
12 16  
13 17 it 'should return the two projects ordered' do
14   - expect(Project.latest(2)).to eq([@kalibro, @qt])
  18 + expect(Project.latest(2)).to eq([another_project, project])
15 19 end
16 20  
17 21 context 'when no parameter is passed' do
18 22 it 'should return just the most recent project' do
19   - expect(Project.latest).to eq([@kalibro])
  23 + expect(Project.latest).to eq([another_project])
20 24 end
21 25 end
22 26 end
  27 +
  28 + describe 'attributes' do
  29 + subject { FactoryGirl.build(:project_with_id) }
  30 +
  31 + let!(:project_attributes) { FactoryGirl.build(:project_attributes) }
  32 +
  33 + before :each do
  34 + ProjectAttributes.expects(:find_by_project_id).returns(project_attributes)
  35 + end
  36 +
  37 + it 'is expected to return the project attributes' do
  38 + expect(subject.attributes).to eq(project_attributes)
  39 + end
  40 + end
23 41 end
24 42 end
... ...
spec/models/user_spec.rb
... ... @@ -10,7 +10,7 @@ describe User, :type =&gt; :model do
10 10 end
11 11  
12 12 describe 'associations' do
13   - it { is_expected.to have_many(:project_ownerships) }
  13 + it { is_expected.to have_many(:project_attributes) }
14 14 it { is_expected.to have_many(:reading_group_ownerships) }
15 15 it { is_expected.to have_many(:kalibro_configuration_ownerships) }
16 16 end
... ... @@ -19,11 +19,11 @@ describe User, :type =&gt; :model do
19 19 describe 'projects' do
20 20 subject { FactoryGirl.build(:user) }
21 21 let(:project) {FactoryGirl.build(:project_with_id)}
22   - let(:project_ownership) {FactoryGirl.build(:project_ownership)}
  22 + let(:project_attributes) {FactoryGirl.build(:project_attributes)}
23 23  
24 24 before :each do
25   - project_ownership.expects(:project).returns(project)
26   - subject.expects(:project_ownerships).returns([project_ownership])
  25 + project_attributes.expects(:project).returns(project)
  26 + subject.expects(:project_attributes).returns([project_attributes])
27 27 end
28 28  
29 29 it 'should return a list of projects owned by the user' do
... ...