Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix minor bug in extra_actions where action isn't passed; improve tests.
- Loading branch information
1 parent
3188bbf
commit 4603f0a
Showing
10 changed files
with
120 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
class Api2::ThingsController < Api2Controller | ||
include RESTFramework::ModelControllerMixin | ||
|
||
class ThingsSerializer < RESTFramework::NativeSerializer | ||
self.action_config = {list: {only: [:id, :name, :price]}} | ||
self.singular_config = {only: [:id, :name, :shape]} | ||
self.plural_config = {only: [:id, :name]} | ||
end | ||
|
||
self.fields = %w(id name) | ||
self.action_fields = { | ||
create_fields: %w(name), | ||
update_fields: %w(name), | ||
} | ||
self.action_fields = {create: %w(name), update: %w(name)} | ||
self.paginator_class = RESTFramework::PageNumberPaginator | ||
self.page_size = 2 | ||
self.serializer_class = ThingsSerializer | ||
self.extra_actions = {alternate_list: :get} | ||
|
||
def alternate_list | ||
return self.index | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require_relative '../base' | ||
|
||
|
||
class Api2::ThingControllerTest < ActionController::TestCase | ||
def test_show | ||
get :show, as: :json | ||
assert_response :success | ||
assert _parsed_body['name'] | ||
assert_nil _parsed_body['shape'] | ||
end | ||
|
||
def test_changed_action | ||
get :changed_action, as: :json | ||
assert_response :success | ||
assert _parsed_body['changed'] | ||
assert_nil _parsed_body['name'] | ||
end | ||
|
||
def test_another_changed_action | ||
get :another_changed_action, as: :json | ||
assert_response :success | ||
assert _parsed_body['another_changed'] | ||
assert_nil _parsed_body['name'] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters