diff --git a/app/api/helpers.rb b/app/api/helpers.rb index f6b21a2..946c05d 100644 --- a/app/api/helpers.rb +++ b/app/api/helpers.rb @@ -403,12 +403,12 @@ module Api end def asset_with_image params - if params.has_key? :image_builder + if !params.nil? && params.has_key?(:image_builder) asset_api_params = params asset_api_params[:image_builder] = base64_to_uploadedfile(asset_api_params[:image_builder]) return asset_api_params end - params + params end def base64_to_uploadedfile(base64_image) diff --git a/app/api/v1/profiles.rb b/app/api/v1/profiles.rb index 42a69b4..b05ec57 100644 --- a/app/api/v1/profiles.rb +++ b/app/api/v1/profiles.rb @@ -28,7 +28,7 @@ module Api authenticate! profile = environment.profiles.find_by(id: params[:id]) return forbidden! unless profile.allow_edit?(current_person) - profile.update_attributes!(params[:profile]) + profile.update_attributes!(asset_with_image(params[:profile])) present profile, :with => Entities::Profile, :current_person => current_person end diff --git a/test/api/profiles_test.rb b/test/api/profiles_test.rb index 6144b02..bd25de9 100644 --- a/test/api/profiles_test.rb +++ b/test/api/profiles_test.rb @@ -218,4 +218,18 @@ class ProfilesTest < ActiveSupport::TestCase json = JSON.parse(last_response.body) assert_includes json["permissions"], 'allow_post_content' end + + should 'update profile image' do + login_api + community = fast_create(Community) + community.add_member(person) + base64_image = create_base64_image + params.merge!({profile: {image_builder: base64_image}}) + assert_nil person.image + post "/api/v1/profiles/#{community.id}?#{params.to_query}" + community.reload + assert_not_nil community.image + assert_equal community.image.filename, base64_image[:filename] + end + end -- libgit2 0.21.2