Commit 03ae4c723593e1a7b652581dcb208f58da1cdf4c
Committed by
Diego Camarinha
1 parent
c5c5ae20
Exists in
colab
and in
4 other branches
Prepare factories and start tests for visibility (code still broken) [no-ci]
Showing
8 changed files
with
63 additions
and
60 deletions
Show diff stats
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 | 3 | name "Java" |
| 4 | 4 | description "Code metrics for Java." |
| 5 | 5 | |
| 6 | 6 | trait :with_id do |
| 7 | - id 1 | |
| 7 | + sequence(:id, 1) | |
| 8 | 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 | 13 | end |
| 20 | - | |
| 21 | - factory :another_kalibro_configuration_with_id, traits: [:with_id] | |
| 22 | 14 | end |
| 23 | 15 | end | ... | ... |
spec/factories/mezuro_configuration_ownerships.rb
spec/factories/reading_group_ownerships.rb
spec/factories/reading_groups.rb
| ... | ... | @@ -4,20 +4,12 @@ FactoryGirl.define do |
| 4 | 4 | description "Cacildis!" |
| 5 | 5 | |
| 6 | 6 | trait :with_id do |
| 7 | - id 1 | |
| 7 | + sequence(:id, 1) | |
| 8 | 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 | 13 | end |
| 20 | - | |
| 21 | - factory :another_reading_group_with_id, traits: [:with_id] | |
| 22 | 14 | end |
| 23 | 15 | -end |
| 16 | +end | |
| 24 | 17 | \ No newline at end of file | ... | ... |
spec/factories/users.rb
spec/models/mezuro_configuration_ownership_spec.rb
spec/models/reading_group_ownership_spec.rb
spec/models/reading_group_spec.rb
| ... | ... | @@ -4,13 +4,13 @@ describe ReadingGroup, :type => :model do |
| 4 | 4 | describe 'methods' do |
| 5 | 5 | describe 'persisted?' do |
| 6 | 6 | before :each do |
| 7 | - @subject = FactoryGirl.build(:reading_group_with_id) | |
| 7 | + @subject = FactoryGirl.build(:reading_group, :with_id) | |
| 8 | 8 | end |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | 11 | describe 'update' do |
| 12 | 12 | before :each do |
| 13 | - @qt = FactoryGirl.build(:reading_group_with_id) | |
| 13 | + @qt = FactoryGirl.build(:reading_group, :with_id) | |
| 14 | 14 | @qt_params = @qt.to_hash |
| 15 | 15 | end |
| 16 | 16 | |
| ... | ... | @@ -36,7 +36,7 @@ describe ReadingGroup, :type => :model do |
| 36 | 36 | end |
| 37 | 37 | |
| 38 | 38 | describe 'readings' do |
| 39 | - subject { FactoryGirl.build(:reading_group_with_id) } | |
| 39 | + subject { FactoryGirl.build(:reading_group, :with_id) } | |
| 40 | 40 | let(:reading) { FactoryGirl.build(:reading_with_id) } |
| 41 | 41 | |
| 42 | 42 | it 'should call readings_of on the Reading model' do |
| ... | ... | @@ -46,4 +46,46 @@ describe ReadingGroup, :type => :model do |
| 46 | 46 | end |
| 47 | 47 | end |
| 48 | 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 | 91 | end | ... | ... |