Commit c609113cfa06f45e4b49945610c61e3be0299262
1 parent
5807ff83
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
fixing unit tests
Showing
7 changed files
with
84 additions
and
84 deletions
Show diff stats
app/models/profile.rb
| ... | ... | @@ -203,9 +203,9 @@ class Profile < ActiveRecord::Base |
| 203 | 203 | Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',') |
| 204 | 204 | end |
| 205 | 205 | |
| 206 | - scope :visible, :conditions => { :visible => true } | |
| 206 | + scope :visible, :conditions => { :visible => true, :secret => false } | |
| 207 | 207 | scope :disabled, :conditions => { :visible => false } |
| 208 | - scope :public, :conditions => { :visible => true, :public_profile => true } | |
| 208 | + scope :public, :conditions => { :visible => true, :public_profile => true, :secret => false } | |
| 209 | 209 | scope :enabled, :conditions => { :enabled => true } |
| 210 | 210 | |
| 211 | 211 | # Subclasses must override this method | ... | ... |
test/unit/api/articles_test.rb
| ... | ... | @@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/test_helper' |
| 3 | 3 | class ArticlesTest < ActiveSupport::TestCase |
| 4 | 4 | |
| 5 | 5 | def setup |
| 6 | - Environment.destroy_all | |
| 7 | 6 | login_api |
| 8 | 7 | end |
| 9 | 8 | |
| ... | ... | @@ -32,7 +31,7 @@ class ArticlesTest < ActiveSupport::TestCase |
| 32 | 31 | end |
| 33 | 32 | |
| 34 | 33 | should 'not return article if user has no permission to view it' do |
| 35 | - person = fast_create(Person) | |
| 34 | + person = fast_create(Person, :environment_id => environment.id) | |
| 36 | 35 | article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) |
| 37 | 36 | assert !article.published? |
| 38 | 37 | |
| ... | ... | @@ -50,7 +49,7 @@ class ArticlesTest < ActiveSupport::TestCase |
| 50 | 49 | end |
| 51 | 50 | |
| 52 | 51 | should 'not list children of forbidden article' do |
| 53 | - person = fast_create(Person) | |
| 52 | + person = fast_create(Person, :environment_id => environment.id) | |
| 54 | 53 | article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) |
| 55 | 54 | child1 = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing") |
| 56 | 55 | child2 = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing") |
| ... | ... | @@ -59,7 +58,7 @@ class ArticlesTest < ActiveSupport::TestCase |
| 59 | 58 | end |
| 60 | 59 | |
| 61 | 60 | should 'not return child of forbidden article' do |
| 62 | - person = fast_create(Person) | |
| 61 | + person = fast_create(Person, :environment_id => environment.id) | |
| 63 | 62 | article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) |
| 64 | 63 | child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing") |
| 65 | 64 | get "/api/v1/articles/#{article.id}/children/#{child.id}?#{params.to_query}" |
| ... | ... | @@ -67,7 +66,7 @@ class ArticlesTest < ActiveSupport::TestCase |
| 67 | 66 | end |
| 68 | 67 | |
| 69 | 68 | should 'not return private child' do |
| 70 | - person = fast_create(Person) | |
| 69 | + person = fast_create(Person, :environment_id => environment.id) | |
| 71 | 70 | article = fast_create(Article, :profile_id => person.id, :name => "Some thing") |
| 72 | 71 | child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing", :published => false) |
| 73 | 72 | get "/api/v1/articles/#{article.id}/children/#{child.id}?#{params.to_query}" |
| ... | ... | @@ -75,7 +74,7 @@ class ArticlesTest < ActiveSupport::TestCase |
| 75 | 74 | end |
| 76 | 75 | |
| 77 | 76 | should 'not list private child' do |
| 78 | - person = fast_create(Person) | |
| 77 | + person = fast_create(Person, :environment_id => environment.id) | |
| 79 | 78 | article = fast_create(Article, :profile_id => person.id, :name => "Some thing") |
| 80 | 79 | child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing", :published => false) |
| 81 | 80 | get "/api/v1/articles/#{article.id}/children?#{params.to_query}" |
| ... | ... | @@ -90,15 +89,15 @@ class ArticlesTest < ActiveSupport::TestCase |
| 90 | 89 | profile_kinds = %w(community person enterprise) |
| 91 | 90 | profile_kinds.each do |kind| |
| 92 | 91 | should "return article by #{kind}" do |
| 93 | - profile = fast_create(kind.camelcase.constantize) | |
| 94 | - article = fast_create(Article, :profile_id => person.id, :name => "Some thing") | |
| 95 | - get "/api/v1/#{kind.pluralize}/#{person.id}/articles/#{article.id}?#{params.to_query}" | |
| 92 | + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) | |
| 93 | + article = fast_create(Article, :profile_id => profile.id, :name => "Some thing") | |
| 94 | + get "/api/v1/#{kind.pluralize}/#{profile.id}/articles/#{article.id}?#{params.to_query}" | |
| 96 | 95 | json = JSON.parse(last_response.body) |
| 97 | 96 | assert_equal article.id, json["article"]["id"] |
| 98 | 97 | end |
| 99 | 98 | |
| 100 | 99 | should "not return article by #{kind} if user has no permission to view it" do |
| 101 | - profile = fast_create(kind.camelcase.constantize) | |
| 100 | + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) | |
| 102 | 101 | article = fast_create(Article, :profile_id => profile.id, :name => "Some thing", :published => false) |
| 103 | 102 | assert !article.published? |
| 104 | 103 | |
| ... | ... | @@ -107,7 +106,7 @@ class ArticlesTest < ActiveSupport::TestCase |
| 107 | 106 | end |
| 108 | 107 | |
| 109 | 108 | should "not list forbidden article when listing articles by #{kind}" do |
| 110 | - profile = fast_create(kind.camelcase.constantize) | |
| 109 | + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) | |
| 111 | 110 | article = fast_create(Article, :profile_id => profile.id, :name => "Some thing", :published => false) |
| 112 | 111 | assert !article.published? |
| 113 | 112 | |
| ... | ... | @@ -124,7 +123,7 @@ class ArticlesTest < ActiveSupport::TestCase |
| 124 | 123 | group_kinds = %w(community enterprise) |
| 125 | 124 | group_kinds.each do |kind| |
| 126 | 125 | should "#{kind}: create article" do |
| 127 | - profile = fast_create(kind.camelcase.constantize) | |
| 126 | + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) | |
| 128 | 127 | give_permission(user.person, 'post_content', profile) |
| 129 | 128 | params[:article] = {:name => "Title"} |
| 130 | 129 | post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" |
| ... | ... | @@ -133,16 +132,16 @@ class ArticlesTest < ActiveSupport::TestCase |
| 133 | 132 | end |
| 134 | 133 | |
| 135 | 134 | should "#{kind}: do not create article if user has no permission to post content" do |
| 136 | - profile = fast_create(kind.camelcase.constantize) | |
| 135 | + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) | |
| 137 | 136 | give_permission(user.person, 'invite_members', profile) |
| 138 | 137 | params[:article] = {:name => "Title"} |
| 139 | 138 | post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" |
| 140 | 139 | assert_equal 403, last_response.status |
| 141 | 140 | end |
| 142 | 141 | |
| 143 | - should "#{kind}: create article with parent" do | |
| 144 | - profile = fast_create(kind.camelcase.constantize) | |
| 145 | - profile.add_member(user.person) | |
| 142 | + should "#{kind} create article with parent" do | |
| 143 | + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) | |
| 144 | + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true) | |
| 146 | 145 | article = fast_create(Article) |
| 147 | 146 | |
| 148 | 147 | params[:article] = {:name => "Title", :parent_id => article.id} |
| ... | ... | @@ -151,9 +150,9 @@ class ArticlesTest < ActiveSupport::TestCase |
| 151 | 150 | assert_equal article.id, json["article"]["parent"]["id"] |
| 152 | 151 | end |
| 153 | 152 | |
| 154 | - should "#{kind}: create article with content type passed as parameter" do | |
| 155 | - profile = fast_create(kind.camelcase.constantize) | |
| 156 | - profile.add_member(user.person) | |
| 153 | + should "#{kind} create article with content type passed as parameter" do | |
| 154 | + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) | |
| 155 | + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true) | |
| 157 | 156 | |
| 158 | 157 | Article.delete_all |
| 159 | 158 | params[:article] = {:name => "Title"} |
| ... | ... | @@ -165,8 +164,8 @@ class ArticlesTest < ActiveSupport::TestCase |
| 165 | 164 | end |
| 166 | 165 | |
| 167 | 166 | should "#{kind}: create article of TinyMceArticle type if no content type is passed as parameter" do |
| 168 | - profile = fast_create(kind.camelcase.constantize) | |
| 169 | - profile.add_member(user.person) | |
| 167 | + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) | |
| 168 | + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true) | |
| 170 | 169 | |
| 171 | 170 | params[:article] = {:name => "Title"} |
| 172 | 171 | post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" |
| ... | ... | @@ -176,7 +175,7 @@ class ArticlesTest < ActiveSupport::TestCase |
| 176 | 175 | end |
| 177 | 176 | |
| 178 | 177 | should "#{kind}: not create article with invalid article content type" do |
| 179 | - profile = fast_create(kind.camelcase.constantize) | |
| 178 | + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) | |
| 180 | 179 | profile.add_member(user.person) |
| 181 | 180 | |
| 182 | 181 | params[:article] = {:name => "Title"} |
| ... | ... | @@ -187,20 +186,20 @@ class ArticlesTest < ActiveSupport::TestCase |
| 187 | 186 | assert_equal 403, last_response.status |
| 188 | 187 | end |
| 189 | 188 | |
| 190 | - should "#{kind}: create article defining the correct profile" do | |
| 191 | - profile = fast_create(kind.camelcase.constantize) | |
| 192 | - profile.add_member(user.person) | |
| 189 | + should "#{kind} create article defining the correct profile" do | |
| 190 | + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) | |
| 191 | + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true) | |
| 193 | 192 | |
| 194 | 193 | params[:article] = {:name => "Title"} |
| 195 | 194 | post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" |
| 196 | 195 | json = JSON.parse(last_response.body) |
| 197 | 196 | |
| 198 | - assert_equal profile, Article.last.profile | |
| 197 | + assert_equal profile.id, json['article']['profile']['id'] | |
| 199 | 198 | end |
| 200 | 199 | |
| 201 | 200 | should "#{kind}: create article defining the created_by" do |
| 202 | - profile = fast_create(kind.camelcase.constantize) | |
| 203 | - profile.add_member(user.person) | |
| 201 | + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) | |
| 202 | + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true) | |
| 204 | 203 | |
| 205 | 204 | params[:article] = {:name => "Title"} |
| 206 | 205 | post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" |
| ... | ... | @@ -210,8 +209,8 @@ class ArticlesTest < ActiveSupport::TestCase |
| 210 | 209 | end |
| 211 | 210 | |
| 212 | 211 | should "#{kind}: create article defining the last_changed_by" do |
| 213 | - profile = fast_create(kind.camelcase.constantize) | |
| 214 | - profile.add_member(user.person) | |
| 212 | + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id) | |
| 213 | + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true) | |
| 215 | 214 | |
| 216 | 215 | params[:article] = {:name => "Title"} |
| 217 | 216 | post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" |
| ... | ... | @@ -233,7 +232,7 @@ class ArticlesTest < ActiveSupport::TestCase |
| 233 | 232 | end |
| 234 | 233 | |
| 235 | 234 | should 'person do not create article if user has no permission to post content' do |
| 236 | - person = fast_create(Person) | |
| 235 | + person = fast_create(Person, :environment_id => environment.id) | |
| 237 | 236 | params[:article] = {:name => "Title"} |
| 238 | 237 | post "/api/v1/people/#{person.id}/articles?#{params.to_query}" |
| 239 | 238 | assert_equal 403, last_response.status | ... | ... |
test/unit/api/categories_test.rb
| ... | ... | @@ -7,25 +7,25 @@ class CategoriesTest < ActiveSupport::TestCase |
| 7 | 7 | end |
| 8 | 8 | |
| 9 | 9 | should 'list categories' do |
| 10 | - category = fast_create(Category) | |
| 10 | + category = fast_create(Category, :environment_id => environment.id) | |
| 11 | 11 | get "/api/v1/categories/?#{params.to_query}" |
| 12 | 12 | json = JSON.parse(last_response.body) |
| 13 | 13 | assert_includes json["categories"].map { |c| c["name"] }, category.name |
| 14 | 14 | end |
| 15 | 15 | |
| 16 | 16 | should 'get category by id' do |
| 17 | - category = fast_create(Category) | |
| 17 | + category = fast_create(Category, :environment_id => environment.id) | |
| 18 | 18 | get "/api/v1/categories/#{category.id}/?#{params.to_query}" |
| 19 | 19 | json = JSON.parse(last_response.body) |
| 20 | 20 | assert_equal category.name, json["category"]["name"] |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | 23 | should 'list parent and children when get category by id' do |
| 24 | - parent = fast_create(Category) | |
| 25 | - child_1 = fast_create(Category) | |
| 26 | - child_2 = fast_create(Category) | |
| 24 | + parent = fast_create(Category, :environment_id => environment.id) | |
| 25 | + child_1 = fast_create(Category, :environment_id => environment.id) | |
| 26 | + child_2 = fast_create(Category, :environment_id => environment.id) | |
| 27 | 27 | |
| 28 | - category = fast_create(Category) | |
| 28 | + category = fast_create(Category, :environment_id => environment.id) | |
| 29 | 29 | category.parent = parent |
| 30 | 30 | category.children << child_1 |
| 31 | 31 | category.children << child_2 |
| ... | ... | @@ -38,11 +38,11 @@ class CategoriesTest < ActiveSupport::TestCase |
| 38 | 38 | end |
| 39 | 39 | |
| 40 | 40 | should 'include parent in categories list if params is true' do |
| 41 | - parent_1 = fast_create(Category) # parent_1 has no parent category | |
| 42 | - child_1 = fast_create(Category) | |
| 43 | - child_2 = fast_create(Category) | |
| 41 | + parent_1 = fast_create(Category, :environment_id => environment.id) # parent_1 has no parent category | |
| 42 | + child_1 = fast_create(Category, :environment_id => environment.id) | |
| 43 | + child_2 = fast_create(Category, :environment_id => environment.id) | |
| 44 | 44 | |
| 45 | - parent_2 = fast_create(Category) | |
| 45 | + parent_2 = fast_create(Category, :environment_id => environment.id) | |
| 46 | 46 | parent_2.parent = parent_1 |
| 47 | 47 | parent_2.children << child_1 |
| 48 | 48 | parent_2.children << child_2 |
| ... | ... | @@ -60,10 +60,10 @@ class CategoriesTest < ActiveSupport::TestCase |
| 60 | 60 | end |
| 61 | 61 | |
| 62 | 62 | should 'include children in categories list if params is true' do |
| 63 | - category = fast_create(Category) | |
| 64 | - child_1 = fast_create(Category) | |
| 65 | - child_2 = fast_create(Category) | |
| 66 | - child_3 = fast_create(Category) | |
| 63 | + category = fast_create(Category, :environment_id => environment.id) | |
| 64 | + child_1 = fast_create(Category, :environment_id => environment.id) | |
| 65 | + child_2 = fast_create(Category, :environment_id => environment.id) | |
| 66 | + child_3 = fast_create(Category, :environment_id => environment.id) | |
| 67 | 67 | |
| 68 | 68 | category.children << child_1 |
| 69 | 69 | category.children << child_2 | ... | ... |
test/unit/api/communities_test.rb
| ... | ... | @@ -8,8 +8,8 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 8 | 8 | end |
| 9 | 9 | |
| 10 | 10 | should 'list only communities' do |
| 11 | - community = fast_create(Community) | |
| 12 | - enterprise = fast_create(Enterprise) # should not list this enterprise | |
| 11 | + community = fast_create(Community, :environment_id => environment.id) | |
| 12 | + enterprise = fast_create(Enterprise, :environment_id => environment.id) # should not list this enterprise | |
| 13 | 13 | get "/api/v1/communities?#{params.to_query}" |
| 14 | 14 | json = JSON.parse(last_response.body) |
| 15 | 15 | assert_not_includes json['communities'].map {|c| c['id']}, enterprise.id |
| ... | ... | @@ -17,16 +17,16 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | 19 | should 'list all communities' do |
| 20 | - community1 = fast_create(Community, :public_profile => true) | |
| 21 | - community2 = fast_create(Community) | |
| 20 | + community1 = fast_create(Community, :environment_id => environment.id, :public_profile => true) | |
| 21 | + community2 = fast_create(Community, :environment_id => environment.id) | |
| 22 | 22 | get "/api/v1/communities?#{params.to_query}" |
| 23 | 23 | json = JSON.parse(last_response.body) |
| 24 | 24 | assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} |
| 25 | 25 | end |
| 26 | 26 | |
| 27 | 27 | should 'not list invisible communities' do |
| 28 | - community1 = fast_create(Community) | |
| 29 | - fast_create(Community, :visible => false) | |
| 28 | + community1 = fast_create(Community, :environment_id => environment.id) | |
| 29 | + fast_create(Community, :environment_id => environment.id, :visible => false) | |
| 30 | 30 | |
| 31 | 31 | get "/api/v1/communities?#{params.to_query}" |
| 32 | 32 | json = JSON.parse(last_response.body) |
| ... | ... | @@ -34,8 +34,8 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 34 | 34 | end |
| 35 | 35 | |
| 36 | 36 | should 'not list private communities without permission' do |
| 37 | - community1 = fast_create(Community) | |
| 38 | - fast_create(Community, :public_profile => false) | |
| 37 | + community1 = fast_create(Community, :environment_id => environment.id) | |
| 38 | + fast_create(Community, :environment_id => environment.id, :public_profile => false) | |
| 39 | 39 | |
| 40 | 40 | get "/api/v1/communities?#{params.to_query}" |
| 41 | 41 | json = JSON.parse(last_response.body) |
| ... | ... | @@ -43,8 +43,8 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 43 | 43 | end |
| 44 | 44 | |
| 45 | 45 | should 'list private community for members' do |
| 46 | - c1 = fast_create(Community) | |
| 47 | - c2 = fast_create(Community, :public_profile => false) | |
| 46 | + c1 = fast_create(Community, :environment_id => environment.id) | |
| 47 | + c2 = fast_create(Community, :environment_id => environment.id, :public_profile => false) | |
| 48 | 48 | c2.add_member(person) |
| 49 | 49 | |
| 50 | 50 | get "/api/v1/communities?#{params.to_query}" |
| ... | ... | @@ -66,7 +66,7 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 66 | 66 | end |
| 67 | 67 | |
| 68 | 68 | should 'get community' do |
| 69 | - community = fast_create(Community) | |
| 69 | + community = fast_create(Community, :environment_id => environment.id) | |
| 70 | 70 | |
| 71 | 71 | get "/api/v1/communities/#{community.id}?#{params.to_query}" |
| 72 | 72 | json = JSON.parse(last_response.body) |
| ... | ... | @@ -74,7 +74,7 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 74 | 74 | end |
| 75 | 75 | |
| 76 | 76 | should 'not get invisible community' do |
| 77 | - community = fast_create(Community, :visible => false) | |
| 77 | + community = fast_create(Community, :environment_id => environment.id, :visible => false) | |
| 78 | 78 | |
| 79 | 79 | get "/api/v1/communities/#{community.id}?#{params.to_query}" |
| 80 | 80 | json = JSON.parse(last_response.body) |
| ... | ... | @@ -82,8 +82,8 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 82 | 82 | end |
| 83 | 83 | |
| 84 | 84 | should 'not get private communities without permission' do |
| 85 | - community = fast_create(Community) | |
| 86 | - fast_create(Community, :public_profile => false) | |
| 85 | + community = fast_create(Community, :environment_id => environment.id) | |
| 86 | + fast_create(Community, :environment_id => environment.id, :public_profile => false) | |
| 87 | 87 | |
| 88 | 88 | get "/api/v1/communities/#{community.id}?#{params.to_query}" |
| 89 | 89 | json = JSON.parse(last_response.body) |
| ... | ... | @@ -91,17 +91,18 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 91 | 91 | end |
| 92 | 92 | |
| 93 | 93 | should 'get private community for members' do |
| 94 | - community = fast_create(Community, :public_profile => false) | |
| 94 | + community = fast_create(Community, :environment_id => environment.id, :public_profile => false, :visible => true) | |
| 95 | 95 | community.add_member(person) |
| 96 | 96 | |
| 97 | + | |
| 97 | 98 | get "/api/v1/communities/#{community.id}?#{params.to_query}" |
| 98 | 99 | json = JSON.parse(last_response.body) |
| 99 | 100 | assert_equal community.id, json['community']['id'] |
| 100 | 101 | end |
| 101 | 102 | |
| 102 | 103 | should 'list person communities' do |
| 103 | - community = fast_create(Community) | |
| 104 | - fast_create(Community) | |
| 104 | + community = fast_create(Community, :environment_id => environment.id) | |
| 105 | + fast_create(Community, :environment_id => environment.id) | |
| 105 | 106 | community.add_member(person) |
| 106 | 107 | |
| 107 | 108 | get "/api/v1/people/#{person.id}/communities?#{params.to_query}" |
| ... | ... | @@ -110,8 +111,8 @@ class CommunitiesTest < ActiveSupport::TestCase |
| 110 | 111 | end |
| 111 | 112 | |
| 112 | 113 | should 'not list person communities invisible' do |
| 113 | - c1 = fast_create(Community) | |
| 114 | - c2 = fast_create(Community, :visible => false) | |
| 114 | + c1 = fast_create(Community, :environment_id => environment.id) | |
| 115 | + c2 = fast_create(Community, :environment_id => environment.id, :visible => false) | |
| 115 | 116 | c1.add_member(person) |
| 116 | 117 | c2.add_member(person) |
| 117 | 118 | ... | ... |
test/unit/api/enterprises_test.rb
| ... | ... | @@ -8,8 +8,8 @@ class EnterprisesTest < ActiveSupport::TestCase |
| 8 | 8 | end |
| 9 | 9 | |
| 10 | 10 | should 'list only enterprises' do |
| 11 | - community = fast_create(Community) # should not list this community | |
| 12 | - enterprise = fast_create(Enterprise, :public_profile => true) | |
| 11 | + community = fast_create(Community, :environment_id => environment.id) # should not list this community | |
| 12 | + enterprise = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true) | |
| 13 | 13 | get "/api/v1/enterprises?#{params.to_query}" |
| 14 | 14 | json = JSON.parse(last_response.body) |
| 15 | 15 | assert_includes json['enterprises'].map {|c| c['id']}, enterprise.id |
| ... | ... | @@ -17,15 +17,15 @@ class EnterprisesTest < ActiveSupport::TestCase |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | 19 | should 'list all enterprises' do |
| 20 | - enterprise1 = fast_create(Enterprise, :public_profile => true) | |
| 21 | - enterprise2 = fast_create(Enterprise) | |
| 20 | + enterprise1 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true) | |
| 21 | + enterprise2 = fast_create(Enterprise, :environment_id => environment.id) | |
| 22 | 22 | get "/api/v1/enterprises?#{params.to_query}" |
| 23 | 23 | json = JSON.parse(last_response.body) |
| 24 | 24 | assert_equivalent [enterprise1.id, enterprise2.id], json['enterprises'].map {|c| c['id']} |
| 25 | 25 | end |
| 26 | 26 | |
| 27 | 27 | should 'not list invisible enterprises' do |
| 28 | - enterprise1 = fast_create(Enterprise) | |
| 28 | + enterprise1 = fast_create(Enterprise, :environment_id => environment.id) | |
| 29 | 29 | fast_create(Enterprise, :visible => false) |
| 30 | 30 | |
| 31 | 31 | get "/api/v1/enterprises?#{params.to_query}" |
| ... | ... | @@ -34,8 +34,8 @@ class EnterprisesTest < ActiveSupport::TestCase |
| 34 | 34 | end |
| 35 | 35 | |
| 36 | 36 | should 'not list private enterprises without permission' do |
| 37 | - enterprise1 = fast_create(Enterprise) | |
| 38 | - fast_create(Enterprise, :public_profile => false) | |
| 37 | + enterprise1 = fast_create(Enterprise, :environment_id => environment.id) | |
| 38 | + fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) | |
| 39 | 39 | |
| 40 | 40 | get "/api/v1/enterprises?#{params.to_query}" |
| 41 | 41 | json = JSON.parse(last_response.body) |
| ... | ... | @@ -43,8 +43,8 @@ class EnterprisesTest < ActiveSupport::TestCase |
| 43 | 43 | end |
| 44 | 44 | |
| 45 | 45 | should 'list private enterprise for members' do |
| 46 | - c1 = fast_create(Enterprise) | |
| 47 | - c2 = fast_create(Enterprise, :public_profile => false) | |
| 46 | + c1 = fast_create(Enterprise, :environment_id => environment.id) | |
| 47 | + c2 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) | |
| 48 | 48 | c2.add_member(person) |
| 49 | 49 | |
| 50 | 50 | get "/api/v1/enterprises?#{params.to_query}" |
| ... | ... | @@ -53,7 +53,7 @@ class EnterprisesTest < ActiveSupport::TestCase |
| 53 | 53 | end |
| 54 | 54 | |
| 55 | 55 | should 'get enterprise' do |
| 56 | - enterprise = fast_create(Enterprise) | |
| 56 | + enterprise = fast_create(Enterprise, :environment_id => environment.id) | |
| 57 | 57 | |
| 58 | 58 | get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" |
| 59 | 59 | json = JSON.parse(last_response.body) |
| ... | ... | @@ -69,8 +69,8 @@ class EnterprisesTest < ActiveSupport::TestCase |
| 69 | 69 | end |
| 70 | 70 | |
| 71 | 71 | should 'not get private enterprises without permission' do |
| 72 | - enterprise = fast_create(Enterprise) | |
| 73 | - fast_create(Enterprise, :public_profile => false) | |
| 72 | + enterprise = fast_create(Enterprise, :environment_id => environment.id) | |
| 73 | + fast_create(Enterprise, :environment_id => environment.id, :public_profile => false) | |
| 74 | 74 | |
| 75 | 75 | get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" |
| 76 | 76 | json = JSON.parse(last_response.body) |
| ... | ... | @@ -87,8 +87,8 @@ class EnterprisesTest < ActiveSupport::TestCase |
| 87 | 87 | end |
| 88 | 88 | |
| 89 | 89 | should 'list person enterprises' do |
| 90 | - enterprise = fast_create(Enterprise) | |
| 91 | - fast_create(Enterprise) | |
| 90 | + enterprise = fast_create(Enterprise, :environment_id => environment.id) | |
| 91 | + fast_create(Enterprise, :environment_id => environment.id) | |
| 92 | 92 | enterprise.add_member(person) |
| 93 | 93 | |
| 94 | 94 | get "/api/v1/people/#{person.id}/enterprises?#{params.to_query}" |
| ... | ... | @@ -97,8 +97,8 @@ class EnterprisesTest < ActiveSupport::TestCase |
| 97 | 97 | end |
| 98 | 98 | |
| 99 | 99 | should 'not list person enterprises invisible' do |
| 100 | - c1 = fast_create(Enterprise) | |
| 101 | - c2 = fast_create(Enterprise, :visible => false) | |
| 100 | + c1 = fast_create(Enterprise, :environment_id => environment.id) | |
| 101 | + c2 = fast_create(Enterprise, :environment_id => environment.id, :visible => false) | |
| 102 | 102 | c1.add_member(person) |
| 103 | 103 | c2.add_member(person) |
| 104 | 104 | ... | ... |
test/unit/api/test_helper.rb
| ... | ... | @@ -9,7 +9,7 @@ class ActiveSupport::TestCase |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | 11 | def login_api |
| 12 | - @environment = fast_create(Environment, :is_default => true) | |
| 12 | + @environment = Environment.default | |
| 13 | 13 | @user = User.create!(:login => 'testapi', :password => 'testapi', :password_confirmation => 'testapi', :email => 'test@test.org', :environment => @environment) |
| 14 | 14 | @user.activate |
| 15 | 15 | @person = @user.person | ... | ... |
test/unit/scrap_test.rb
| ... | ... | @@ -218,7 +218,7 @@ class ScrapTest < ActiveSupport::TestCase |
| 218 | 218 | should "update the scrap on reply creation" do |
| 219 | 219 | person = create_user.person |
| 220 | 220 | s = fast_create(Scrap, :updated_at => DateTime.parse('2010-01-01')) |
| 221 | - assert_equal DateTime.parse('2010-01-01'), s.updated_at.strftime('%Y-%m-%d') | |
| 221 | + assert_equal DateTime.parse('2010-01-01'), s.updated_at | |
| 222 | 222 | DateTime.stubs(:now).returns(DateTime.parse('2010-09-07')) |
| 223 | 223 | s1 = create(Scrap, :content => 'some content', :sender => person, :receiver => person, :scrap_id => s.id) |
| 224 | 224 | s.reload | ... | ... |