Skip to content

Commit

Permalink
return absolute path instead of full url in serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
codez committed Mar 15, 2017
1 parent 8706607 commit ead25cd
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/archive_formats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def model_scope
end

def entry_url
admin_profile_archive_format_url(profile, entry)
admin_profile_archive_format_path(profile, entry)
end

def profile
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/downgrade_actions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def model_scope
end

def entry_url
admin_profile_archive_format_downgrade_action_url(profile, archive_format, entry)
admin_profile_archive_format_downgrade_action_path(profile, archive_format, entry)
end

def archive_format
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/shows/merge_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def merge_shows(source, target)
end

def render_show(show)
render json: show, location: admin_show_url(show), serializer: Admin::ShowSerializer
render json: show, location: admin_show_path(show), serializer: Admin::ShowSerializer
end

end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/crud_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def destroy

def entry_url
prefix = self.class.name.deconstantize.underscore.tr('/', '_')
send("#{prefix}_#{entry.class.model_name.singular_route_key}_url", entry)
send("#{prefix}_#{entry.class.model_name.singular_route_key}_path", entry)
end

def build_entry
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/admin/archive_format_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ArchiveFormatSerializer < ApplicationSerializer
attributes :id, :codec, :initial_bitrate, :initial_channels, :max_public_bitrate,
:created_at, :updated_at

link(:self) { admin_profile_archive_format_url(object.profile_id, object) }
link(:self) { admin_profile_archive_format_path(object.profile_id, object) }

end
end
2 changes: 1 addition & 1 deletion app/serializers/admin/downgrade_action_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DowngradeActionSerializer < ApplicationSerializer
attributes :id, :months, :bitrate, :channels

link(:self) do
admin_profile_archive_format_downgrade_action_url(
admin_profile_archive_format_downgrade_action_path(
object.profile,
object.archive_format_id,
object
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/admin/playback_format_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PlaybackFormatSerializer < ApplicationSerializer

attributes :id, :name, :description, :codec, :bitrate, :channels, :created_at, :updated_at

link(:self) { admin_playback_format_url(object) }
link(:self) { admin_playback_format_path(object) }

end
end
2 changes: 1 addition & 1 deletion app/serializers/admin/profile_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ProfileSerializer < ApplicationSerializer

attributes :id, :name, :description, :default, :created_at, :updated_at

link(:self) { admin_profile_url(object) }
link(:self) { admin_profile_path(object) }

end
end
2 changes: 1 addition & 1 deletion app/serializers/admin/show_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ShowSerializer < ApplicationSerializer

belongs_to :profile, serializer: ProfileSerializer

link(:self) { admin_show_url(object) }
link(:self) { admin_show_path(object) }

end
end
2 changes: 1 addition & 1 deletion app/serializers/admin/user_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class UserSerializer < ApplicationSerializer

attribute :admin?, key: :admin

link(:self) { admin_user_url(object) }
link(:self) { admin_user_path(object) }

def groups
object.group_list
Expand Down
4 changes: 2 additions & 2 deletions app/serializers/audio_file_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class AudioFileSerializer < ApplicationSerializer
attributes :codec, :bitrate, :channels, :playback_format, :url

# duplication required as we are in a different scope inside the link block.
link(:self) { audio_file_url(AudioPath.new(object).url_params) }
link(:self) { audio_file_path(AudioPath.new(object).url_params) }

def url
audio_file_url(audio_path.url_params)
audio_file_path(audio_path.url_params)
end

def playback_format
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/show_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class ShowSerializer < ApplicationSerializer

attributes :id, :name, :details

link(:self) { show_url(object) }
link(:self) { show_path(object) }

end
16 changes: 8 additions & 8 deletions test/controllers/audio_files_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class AudioFilesControllerTest < ActionController::TestCase

assert_equal [320, 192, 96], json_attrs(:bitrate)
assert_equal %w(best high low), json_attrs('playback_format')
assert_equal ['http://example.com/audio_files/2013/04/10/110000_best.mp3',
'http://example.com/audio_files/2013/04/10/110000_high.mp3',
'http://example.com/audio_files/2013/04/10/110000_low.mp3'],
assert_equal ['/audio_files/2013/04/10/110000_best.mp3',
'/audio_files/2013/04/10/110000_high.mp3',
'/audio_files/2013/04/10/110000_low.mp3'],
json_attrs(:url)
json_links = json['data'].collect { |s| s['links']['self'] }
assert_equal json_attrs(:url), json_links
Expand All @@ -24,8 +24,8 @@ class AudioFilesControllerTest < ActionController::TestCase

assert_equal [192, 96], json_attrs(:bitrate)
assert_equal %w(high low), json_attrs('playback_format')
assert_equal ['http://example.com/audio_files/2013/04/10/110000_high.mp3',
'http://example.com/audio_files/2013/04/10/110000_low.mp3'],
assert_equal ['/audio_files/2013/04/10/110000_high.mp3',
'/audio_files/2013/04/10/110000_low.mp3'],
json_attrs(:url)
end

Expand All @@ -36,9 +36,9 @@ class AudioFilesControllerTest < ActionController::TestCase

assert_equal [320, 192, 96], json_attrs(:bitrate)
assert_equal %w(best high low), json_attrs('playback_format')
assert_equal ['http://example.com/audio_files/2013/04/10/110000_best.mp3',
'http://example.com/audio_files/2013/04/10/110000_high.mp3',
'http://example.com/audio_files/2013/04/10/110000_low.mp3'],
assert_equal ['/audio_files/2013/04/10/110000_best.mp3',
'/audio_files/2013/04/10/110000_high.mp3',
'/audio_files/2013/04/10/110000_low.mp3'],
json_attrs(:url)
end

Expand Down

0 comments on commit ead25cd

Please sign in to comment.