diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a7a0678..0b04773f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Fixed + +- [#286][]: Change `file` filter to check for `rewind` instead of `eof?`. + # [2.0.0][] (2015-05-06) For help upgrading to version 2, please read [the announcement post][]. @@ -546,5 +550,6 @@ For help upgrading to version 2, please read [the announcement post][]. [#264]: https://github.com/orgsync/active_interaction/issues/264 [#265]: https://github.com/orgsync/active_interaction/issues/265 [#269]: https://github.com/orgsync/active_interaction/issues/269 + [#286]: https://github.com/orgsync/active_interaction/issues/286 [the announcement post]: http://devblog.orgsync.com/2015/05/06/announcing-active-interaction-2/ diff --git a/active_interaction.gemspec b/active_interaction.gemspec index 7e732494..3d82ca52 100644 --- a/active_interaction.gemspec +++ b/active_interaction.gemspec @@ -34,17 +34,18 @@ Gem::Specification.new do |gem| gem.add_dependency 'activemodel', '>= 3.2', '<5' { - 'bundler' => '~> 1.9', - 'coveralls' => '~> 0.8', - 'guard-rspec' => '~> 4.5', - 'guard-rubocop' => '~> 1.2', - 'kramdown' => '~> 1.7', - 'rake' => '~> 10.4', - 'rspec' => '~> 3.2', - 'rubocop' => '~> 0.30', - 'yard' => '~> 0.8' - }.each do |name, version| - gem.add_development_dependency name, version + 'actionpack' => ['>= 3.2', '< 5'], + 'bundler' => ['~> 1.9'], + 'coveralls' => ['~> 0.8'], + 'guard-rspec' => ['~> 4.5'], + 'guard-rubocop' => ['~> 1.2'], + 'kramdown' => ['~> 1.7'], + 'rake' => ['~> 10.4'], + 'rspec' => ['~> 3.2'], + 'rubocop' => ['~> 0.30'], + 'yard' => ['~> 0.8'] + }.each do |name, versions| + gem.add_development_dependency name, *versions end if RUBY_ENGINE == 'rbx' diff --git a/lib/active_interaction/filters/file_filter.rb b/lib/active_interaction/filters/file_filter.rb index 7e755a81..c1d70783 100644 --- a/lib/active_interaction/filters/file_filter.rb +++ b/lib/active_interaction/filters/file_filter.rb @@ -4,8 +4,9 @@ module ActiveInteraction class Base # @!method self.file(*attributes, options = {}) # Creates accessors for the attributes and ensures that values passed to - # the attributes respond to the `eof?` method. This is useful when passing - # in Rails params that include a file upload or another generic IO object. + # the attributes respond to the `rewind` method. This is useful when + # passing in Rails params that include a file upload or another generic + # IO object. # # @!macro filter_method_params # @@ -24,7 +25,7 @@ def database_column_type private def methods - [:eof?] + [:rewind] end end end diff --git a/spec/active_interaction/filters/file_filter_spec.rb b/spec/active_interaction/filters/file_filter_spec.rb index 6022ab71..b15d215b 100644 --- a/spec/active_interaction/filters/file_filter_spec.rb +++ b/spec/active_interaction/filters/file_filter_spec.rb @@ -25,8 +25,8 @@ end end - context 'with an object that responds to #eof?' do - let(:value) { double(eof?: true) } + context 'with an object that responds to #rewind' do + let(:value) { double(rewind: nil) } it 'returns the object' do expect(result).to eq value diff --git a/spec/active_interaction/integration/file_interaction_spec.rb b/spec/active_interaction/integration/file_interaction_spec.rb index ca5d689a..76e68a73 100644 --- a/spec/active_interaction/integration/file_interaction_spec.rb +++ b/spec/active_interaction/integration/file_interaction_spec.rb @@ -1,7 +1,20 @@ # coding: utf-8 require 'spec_helper' +require 'action_dispatch' -describe 'FileInteraction' do +FileInteraction = Class.new(TestInteraction) do + file :a +end + +describe FileInteraction do + include_context 'interactions' it_behaves_like 'an interaction', :file, -> { File.open(__FILE__) } + + it 'works with an uploaded file' do + file = File.open(__FILE__) + uploaded_file = ActionDispatch::Http::UploadedFile.new(tempfile: file) + inputs[:a] = uploaded_file + expect(outcome).to be_valid + end end