Commit 03ae4c723593e1a7b652581dcb208f58da1cdf4c

Authored by Daniel
Committed by Diego Camarinha
1 parent c5c5ae20

Prepare factories and start tests for visibility (code still broken) [no-ci]

spec/factories/kalibro_configurations.rb
1 - FactoryGirl.define do  
2 - factory :kalibro_configuration, class: KalibroConfiguration do 1 +FactoryGirl.define do
  2 + factory :kalibro_configuration do
3 name "Java" 3 name "Java"
4 description "Code metrics for Java." 4 description "Code metrics for Java."
5 5
6 trait :with_id do 6 trait :with_id do
7 - id 1 7 + sequence(:id, 1)
8 end 8 end
9 9
10 - factory :kalibro_configuration_with_id, traits: [:with_id]  
11 - end  
12 -  
13 - factory :another_kalibro_configuration, class: KalibroConfiguration do  
14 - name "Perl"  
15 - description "Code metrics for Perl."  
16 -  
17 - trait :with_id do  
18 - id 12 10 + factory :another_kalibro_configuration do
  11 + name "Perl"
  12 + description "Code metrics for Perl."
19 end 13 end
20 -  
21 - factory :another_kalibro_configuration_with_id, traits: [:with_id]  
22 end 14 end
23 end 15 end
spec/factories/mezuro_configuration_ownerships.rb
@@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
1 -# Read about factories at https://github.com/thoughtbot/factory_girl  
2 -  
3 -FactoryGirl.define do  
4 - factory :kalibro_configuration_ownership do  
5 - user_id 1  
6 - kalibro_configuration_id 1  
7 - end  
8 -end  
spec/factories/reading_group_ownerships.rb
@@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
1 -# Read about factories at https://github.com/thoughtbot/factory_girl  
2 -  
3 -FactoryGirl.define do  
4 - factory :reading_group_ownership do  
5 - user_id 1  
6 - reading_group_id 1  
7 - end  
8 -end  
spec/factories/reading_groups.rb
@@ -4,20 +4,12 @@ FactoryGirl.define do @@ -4,20 +4,12 @@ FactoryGirl.define do
4 description "Cacildis!" 4 description "Cacildis!"
5 5
6 trait :with_id do 6 trait :with_id do
7 - id 1 7 + sequence(:id, 1)
8 end 8 end
9 9
10 - factory :reading_group_with_id, traits: [:with_id]  
11 - end  
12 -  
13 - factory :another_reading_group, class: ReadingGroup do  
14 - name "My Reading Group"  
15 - description "The best one"  
16 -  
17 - trait :with_id do  
18 - id 2 10 + factory :another_reading_group do
  11 + name "My Reading Group"
  12 + description "The best one"
19 end 13 end
20 -  
21 - factory :another_reading_group_with_id, traits: [:with_id]  
22 end 14 end
23 -end 15 -end
  16 +end
24 \ No newline at end of file 17 \ No newline at end of file
spec/factories/users.rb
@@ -6,5 +6,12 @@ FactoryGirl.define do @@ -6,5 +6,12 @@ FactoryGirl.define do
6 name "Diego Martinez" 6 name "Diego Martinez"
7 email "diego@email.com" 7 email "diego@email.com"
8 password "password" 8 password "password"
  9 +
  10 + factory :another_user do
  11 + id 2
  12 + name "Heitor Reis"
  13 + email "hr@email.com"
  14 + password "password"
  15 + end
9 end 16 end
10 end 17 end
spec/models/mezuro_configuration_ownership_spec.rb
@@ -1,7 +0,0 @@ @@ -1,7 +0,0 @@
1 -require 'rails_helper'  
2 -  
3 -describe KalibroConfigurationOwnership, :type => :model do  
4 - describe 'associations' do  
5 - it { is_expected.to belong_to(:user) }  
6 - end  
7 -end  
spec/models/reading_group_ownership_spec.rb
@@ -1,7 +0,0 @@ @@ -1,7 +0,0 @@
1 -require 'rails_helper'  
2 -  
3 -describe ReadingGroupOwnership, :type => :model do  
4 - describe 'associations' do  
5 - it { is_expected.to belong_to(:user) }  
6 - end  
7 -end  
spec/models/reading_group_spec.rb
@@ -4,13 +4,13 @@ describe ReadingGroup, :type => :model do @@ -4,13 +4,13 @@ describe ReadingGroup, :type => :model do
4 describe 'methods' do 4 describe 'methods' do
5 describe 'persisted?' do 5 describe 'persisted?' do
6 before :each do 6 before :each do
7 - @subject = FactoryGirl.build(:reading_group_with_id) 7 + @subject = FactoryGirl.build(:reading_group, :with_id)
8 end 8 end
9 end 9 end
10 10
11 describe 'update' do 11 describe 'update' do
12 before :each do 12 before :each do
13 - @qt = FactoryGirl.build(:reading_group_with_id) 13 + @qt = FactoryGirl.build(:reading_group, :with_id)
14 @qt_params = @qt.to_hash 14 @qt_params = @qt.to_hash
15 end 15 end
16 16
@@ -36,7 +36,7 @@ describe ReadingGroup, :type => :model do @@ -36,7 +36,7 @@ describe ReadingGroup, :type => :model do
36 end 36 end
37 37
38 describe 'readings' do 38 describe 'readings' do
39 - subject { FactoryGirl.build(:reading_group_with_id) } 39 + subject { FactoryGirl.build(:reading_group, :with_id) }
40 let(:reading) { FactoryGirl.build(:reading_with_id) } 40 let(:reading) { FactoryGirl.build(:reading_with_id) }
41 41
42 it 'should call readings_of on the Reading model' do 42 it 'should call readings_of on the Reading model' do
@@ -46,4 +46,46 @@ describe ReadingGroup, :type => :model do @@ -46,4 +46,46 @@ describe ReadingGroup, :type => :model do
46 end 46 end
47 end 47 end
48 end 48 end
  49 +
  50 + describe 'class methods' do
  51 + describe 'public_or_owned_by_user' do
  52 + def build_attrs(rg_iter, *traits, **params)
  53 + FactoryGirl.build(:reading_group_attributes, :with_id, *traits, params.merge(reading_group: rg_iter.next))
  54 + end
  55 +
  56 + let!(:reading_groups) { FactoryGirl.build_list(:reading_group, 4, :with_id) }
  57 + let!(:rgs_iter) { reading_groups.each }
  58 +
  59 + let!(:one_user) { FactoryGirl.build(:user) }
  60 + let!(:other_user) { FactoryGirl.build(:another_user) }
  61 +
  62 + let!(:ones_private_attrs) { build_attrs(rgs_iter, user: one_user) }
  63 + let!(:others_private_attrs) { build_attrs(rgs_iter, user: other_user) }
  64 + let!(:ones_public_attrs) { build_attrs(rgs_iter, :public, user: one_user) }
  65 + let!(:others_public_attrs) { build_attrs(rgs_iter, :public, user: other_user) }
  66 +
  67 + let!(:public_attrs) { [ones_public_attrs, others_public_attrs] }
  68 + let(:public_reading_groups) { public_attrs.map(&:reading_group) }
  69 +
  70 + let(:ones_or_public_attrs) { public_attrs + [ones_private_attrs] }
  71 + let(:ones_or_public_reading_groups) { ones_or_public_attrs.map(&:reading_group) }
  72 +
  73 + before :each do
  74 + # Map the reading group attributes to the corresponding Reading Group
  75 + ReadingGroup.expects(:find).with(kind_of(Integer)) do |id|
  76 + reading_groups.find { |rg| rg.id == id }
  77 + end
  78 + end
  79 +
  80 + context 'when user is nil' do
  81 + before do
  82 + ReadingGroupAttributes.expects(:where).with(public: true).returns(public_attrs)
  83 + end
  84 +
  85 + it 'should find all public reading groups' do
  86 + expect(ReadingGroupAttributes.public_or_owned_by_user(nil)).to eq(public_reading_groups)
  87 + end
  88 + end
  89 + end
  90 + end
49 end 91 end