Commit 9f7261cd52cd058191f150fa39205324d10725ed
1 parent
36701ca8
Exists in
master
and in
27 other branches
rails3: fix organization tests
Also moving profile extension to make count use distinct by default to ActiveRecord::Calculations module.
Showing
3 changed files
with
16 additions
and
18 deletions
Show diff stats
app/models/profile.rb
... | ... | @@ -98,15 +98,6 @@ class Profile < ActiveRecord::Base |
98 | 98 | members.count |
99 | 99 | end |
100 | 100 | |
101 | - class << self | |
102 | - def count_with_distinct(*args) | |
103 | - options = args.last || {} | |
104 | - count_without_distinct(:id, {:distinct => true}.merge(options)) | |
105 | - end | |
106 | - alias_method_chain :count, :distinct | |
107 | - end | |
108 | - | |
109 | - | |
110 | 101 | def members_by_role(role) |
111 | 102 | Person.members_of(self).all(:conditions => ['role_assignments.role_id = ?', role.id]) |
112 | 103 | end | ... | ... |
lib/noosfero/core_ext/active_record.rb
... | ... | @@ -27,3 +27,10 @@ class ActiveRecord::Base |
27 | 27 | end |
28 | 28 | |
29 | 29 | end |
30 | + | |
31 | +ActiveRecord::Calculations.module_eval do | |
32 | + def count_with_default_distinct(column_name=:id, options={}) | |
33 | + count_without_default_distinct(column_name, {:distinct => true}.merge(options)) | |
34 | + end | |
35 | + alias_method_chain :count, :default_distinct | |
36 | +end | ... | ... |
test/unit/organization_test.rb
... | ... | @@ -21,7 +21,7 @@ class OrganizationTest < ActiveSupport::TestCase |
21 | 21 | :requestor => requestor, |
22 | 22 | :target => org, |
23 | 23 | } |
24 | - CreateEnterprise.create!(data) | |
24 | + create(CreateEnterprise, data) | |
25 | 25 | end |
26 | 26 | |
27 | 27 | |
... | ... | @@ -97,7 +97,7 @@ class OrganizationTest < ActiveSupport::TestCase |
97 | 97 | end |
98 | 98 | |
99 | 99 | should 'list contact_email plus admin emails as "notification emails"' do |
100 | - o = Organization.new(:contact_email => 'org@email.com') | |
100 | + o = build(Organization, :contact_email => 'org@email.com') | |
101 | 101 | admin1 = mock; admin1.stubs(:email).returns('admin1@email.com') |
102 | 102 | admin2 = mock; admin2.stubs(:email).returns('admin2@email.com') |
103 | 103 | o.stubs(:admins).returns([admin1, admin2]) |
... | ... | @@ -106,7 +106,7 @@ class OrganizationTest < ActiveSupport::TestCase |
106 | 106 | end |
107 | 107 | |
108 | 108 | should 'list only admins if contact_email is nil' do |
109 | - o = Organization.new(:contact_email => nil) | |
109 | + o = build(Organization, :contact_email => nil) | |
110 | 110 | admin1 = mock; admin1.stubs(:email).returns('admin1@email.com') |
111 | 111 | admin2 = mock; admin2.stubs(:email).returns('admin2@email.com') |
112 | 112 | o.stubs(:admins).returns([admin1, admin2]) |
... | ... | @@ -115,7 +115,7 @@ class OrganizationTest < ActiveSupport::TestCase |
115 | 115 | end |
116 | 116 | |
117 | 117 | should 'list only admins if contact_email is a blank string' do |
118 | - o = Organization.new(:contact_email => '') | |
118 | + o = build(Organization, :contact_email => '') | |
119 | 119 | admin1 = mock; admin1.stubs(:email).returns('admin1@email.com') |
120 | 120 | admin2 = mock; admin2.stubs(:email).returns('admin2@email.com') |
121 | 121 | o.stubs(:admins).returns([admin1, admin2]) |
... | ... | @@ -124,13 +124,13 @@ class OrganizationTest < ActiveSupport::TestCase |
124 | 124 | end |
125 | 125 | |
126 | 126 | should 'return empty array if contact_email is a blank string and it has no admin' do |
127 | - o = Organization.new(:contact_email => '', :environment => Environment.default) | |
127 | + o = build(Organization, :contact_email => '', :environment => Environment.default) | |
128 | 128 | assert_equal [], o.notification_emails |
129 | 129 | end |
130 | 130 | |
131 | 131 | should 'list pending enterprise validations' do |
132 | 132 | org = Organization.new |
133 | - assert_kind_of Array, org.pending_validations | |
133 | + assert_kind_of ActiveRecord::Relation, org.pending_validations | |
134 | 134 | end |
135 | 135 | |
136 | 136 | should 'be able to find a pending validation by its code' do |
... | ... | @@ -148,7 +148,7 @@ class OrganizationTest < ActiveSupport::TestCase |
148 | 148 | |
149 | 149 | should 'be able to find already processed validations' do |
150 | 150 | org = Organization.new |
151 | - assert_kind_of Array, org.processed_validations | |
151 | + assert_kind_of ActiveRecord::Relation, org.processed_validations | |
152 | 152 | end |
153 | 153 | |
154 | 154 | should 'be able to find an already processed validation by its code' do |
... | ... | @@ -160,7 +160,7 @@ class OrganizationTest < ActiveSupport::TestCase |
160 | 160 | end |
161 | 161 | |
162 | 162 | should 'have boxes and blocks upon creation' do |
163 | - profile = Organization.create!(:name => 'test org', :identifier => 'testorg') | |
163 | + profile = create(Organization, :name => 'test org', :identifier => 'testorg') | |
164 | 164 | |
165 | 165 | assert profile.boxes.size > 0 |
166 | 166 | assert profile.blocks.size > 0 |
... | ... | @@ -391,7 +391,7 @@ class OrganizationTest < ActiveSupport::TestCase |
391 | 391 | end |
392 | 392 | |
393 | 393 | should 'validates format of cnpj' do |
394 | - organization = Organization.new(:cnpj => '239-234.234') | |
394 | + organization = build(Organization, :cnpj => '239-234.234') | |
395 | 395 | organization.valid? |
396 | 396 | assert organization.errors[:cnpj.to_s].present? |
397 | 397 | ... | ... |