Skip to content

Commit

Permalink
Merge pull request #1674 from plataformatec/let-remote-url
Browse files Browse the repository at this point in the history
Replace `_url` with `remote_url`
  • Loading branch information
tegon committed Oct 4, 2019
2 parents 67deb18 + a8064eb commit 9385f4e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Unreleased

### Bug fix
* Replace `_url` with `remote_url` when trying to guess file inputs [@tegon](https://github.com/tegon). This has the side-effect of changing carrierwave's support from `0.2.1` to `0.2.2`.

## 5.0.0

### Enhancements
Expand Down
7 changes: 3 additions & 4 deletions lib/simple_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -580,18 +580,17 @@ def find_custom_type(attribute_name)
#
# Note: This does not support multiple file upload inputs, as this is very application-specific.
#
# The order here was choosen based on the popularity of Gems and for commodity - e.g. the method
# with the suffix `_url` is present in three Gems, so it's checked with priority:
# The order here was chosen based on the popularity of Gems:
#
# - `#{attribute_name}_attachment` - ActiveStorage >= `5.2` and Refile >= `0.2.0` <= `0.4.0`
# - `#{attribute_name}_url` - Shrine >= `0.9.0`, Refile >= `0.6.0` and CarrierWave >= `0.2.1`
# - `remote_#{attribute_name}_url` - Refile >= `0.3.0` and CarrierWave >= `0.2.2`
# - `#{attribute_name}_attacher` - Refile >= `0.4.0` and Shrine >= `0.9.0`
# - `#{attribute_name}_file_name` - Paperclip ~> `2.0` (added for backwards compatibility)
#
# Returns a Boolean.
def file_method?(attribute_name)
@object.respond_to?("#{attribute_name}_attachment") ||
@object.respond_to?("#{attribute_name}_url") ||
@object.respond_to?("remote_#{attribute_name}_url") ||
@object.respond_to?("#{attribute_name}_attacher") ||
@object.respond_to?("#{attribute_name}_file_name")
end
Expand Down
2 changes: 1 addition & 1 deletion test/form_builder/general_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def with_custom_form_for(object, *args, &block)
assert_select 'form input#user_with_attachment_avatar.file'
end

test 'builder generates file input for Shrine >= 0.9.0, Refile >= 0.6.0 and CarrierWave >= 0.2.1' do
test 'builder generates file input for Refile >= 0.3.0 and CarrierWave >= 0.2.2' do
with_form_for UserWithAttachment.build, :cover
assert_select 'form input#user_with_attachment_cover.file'
end
Expand Down
2 changes: 1 addition & 1 deletion test/support/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def avatar_attachment
OpenStruct.new
end

def cover_url
def remote_cover_url
"/uploads/cover.png"
end

Expand Down

0 comments on commit 9385f4e

Please sign in to comment.