cirandas.net

commit 78a37e85517ce32c2c7dfa7a52047dd3de5554ca

Author: Leandro Nunes <leandronunes@gmail.com>

Merge branch 'api-profile-theme' into 'master'

api: return environment theme when profile theme is not defined

See merge request !1211

 app/api/entities.rb | 4 +++-
 test/api/profiles_test.rb | 16 ++++++++++++++++


diff --git a/app/api/entities.rb b/app/api/entities.rb
index 7fc9e114bbb01f052959b264e10c88d0c2dffd73..78416d0eb9f602f2a2c3a58d9487d9c43e90ffe0 100644
--- a/app/api/entities.rb
+++ b/app/api/entities.rb
@@ -148,7 +148,9 @@       expose :permissions do |profile, options|
         Entities.permissions_for_entity(profile, options[:current_person],
         :allow_post_content?, :allow_edit?, :allow_destroy?)
       end
-      expose :theme
+      expose :theme do |profile, options|
+        profile.theme || profile.environment.theme
+      end
     end
 
     class UserBasic < Entity




diff --git a/test/api/profiles_test.rb b/test/api/profiles_test.rb
index 0351ab58c00bede1281eae28969d13b044b1b93a..4b74b7496aae53d2129618fe491856b3735a46f9 100644
--- a/test/api/profiles_test.rb
+++ b/test/api/profiles_test.rb
@@ -413,4 +413,20 @@     get "/api/v1/profiles/profile.test?#{params.to_query}"
     json = JSON.parse(last_response.body)
     assert_equal some_person.id, json['id']
   end
+
+  should "return profile theme when it is defined" do
+    some_person = fast_create(Person, theme: 'person-theme')
+    get "/api/v1/profiles/#{some_person.id}?#{params.to_query}"
+    json = JSON.parse(last_response.body)
+    assert_equal 'person-theme', json['theme']
+  end
+
+  should "return environment theme when profile theme is not defined" do
+    some_person = fast_create(Person)
+    environment = some_person.environment
+    environment.update_attribute(:theme, 'environment-theme')
+    get "/api/v1/profiles/#{some_person.id}?#{params.to_query}"
+    json = JSON.parse(last_response.body)
+    assert_equal 'environment-theme', json['theme']
+  end
 end