Skip to content

Commit

Permalink
Fix #201; fail early when given format for TimeZone
Browse files Browse the repository at this point in the history
  • Loading branch information
tfausak committed Aug 14, 2014
1 parent 3dcde28 commit 183683f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/active_interaction/filters/time_filter.rb
Expand Up @@ -26,6 +26,14 @@ class TimeFilter < AbstractDateTimeFilter
alias_method :_klass, :klass
private :_klass

def initialize(name, options = {}, &block)
if options.key?(:format) && klass != Time
fail InvalidFilterError, 'format option unsupported with time zones'
end

super
end

def cast(value)
case value
when Numeric
Expand Down
20 changes: 20 additions & 0 deletions spec/active_interaction/filters/time_filter_spec.rb
Expand Up @@ -14,6 +14,26 @@
end
end

describe '#initialize' do
context 'with a format' do
before { options[:format] = '%T' }

context 'with a time zone' do
before do
time_zone = double
allow(Time).to receive(:zone).and_return(time_zone)

time_with_zone = double
allow(time_zone).to receive(:at).and_return(time_with_zone)
end

it 'raises an error' do
expect { filter }.to raise_error(ActiveInteraction::InvalidFilterError)
end
end
end
end

describe '#cast' do
let(:result) { filter.cast(value) }

Expand Down

0 comments on commit 183683f

Please sign in to comment.