Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/awesome_print/ext/active_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def cast_with_active_support(object, type)
cast = :active_support_time
elsif object.is_a?(::HashWithIndifferentAccess)
cast = :hash_with_indifferent_access
elsif defined?(::ActionController::Parameters) && object.is_a?(::ActionController::Parameters)
cast = :action_controller_parameters
end
end
cast
Expand All @@ -34,6 +36,12 @@ def awesome_active_support_time(object)
def awesome_hash_with_indifferent_access(object)
awesome_hash(object)
end

# Format ActionController::Parameters as standard Hash.
#------------------------------------------------------------------------------
def awesome_action_controller_parameters(object)
awesome_hash(object.to_unsafe_h)
end
end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/ext/active_support_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
expect(@ap.send(:awesome, hash)).to eq("{\n \"hello\"\e[0;37m => \e[0m\e[0;33m\"world\"\e[0m\n}")
end

it 'should format ActionController::Parameters as regular Hash', skip: !defined?(ActionController::Parameters) do
params = ActionController::Parameters.new({ hello: 'world' })
expect(@ap.send(:awesome, params)).to eq("{\n \"hello\"\e[0;37m => \e[0m\e[0;33m\"world\"\e[0m\n}")
end

# ActiveSupport sticks in instance variables to the date object. Make sure
# we ignore that and format Date instance as regular date.
it 'should formate Date object as date' do
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
active_record
action_view
active_support/all
action_controller
mongoid
mongo_mapper
ripple nobrainer
Expand Down