-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from procore/support-class-inheritance
[ZL-452] Support class inheritance
- Loading branch information
Showing
4 changed files
with
72 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require "test_helper" | ||
|
||
class PostsInheritanceTest < ActionDispatch::IntegrationTest | ||
test "it works" do | ||
post = Post.create! | ||
|
||
get("/posts_alt") | ||
|
||
json = JSON.parse(@response.body) | ||
assert_equal 1, json.size | ||
assert_equal(post.id, json.first["id"]) | ||
end | ||
|
||
test "it inherits filter from parent controller" do | ||
post = Post.create! | ||
Post.create! | ||
|
||
get("/posts_alt", params: { filters: { id: post.id } }) | ||
|
||
json = JSON.parse(@response.body) | ||
assert_equal 1, json.size | ||
assert_equal post.id, json.first["id"] | ||
end | ||
|
||
test "it inherits sort from parent controller" do | ||
Post.create!(title: "z") | ||
Post.create!(title: "a") | ||
|
||
get("/posts_alt", params: { sort: "title" }) | ||
|
||
json = JSON.parse(@response.body, object_class: OpenStruct) | ||
assert_equal ["a", "z"], json.map(&:title) | ||
end | ||
|
||
test "it overrides inherited body filter with priority filter" do | ||
Post.create!(priority: 3) | ||
Post.create!(priority: 1) | ||
Post.create!(priority: 2) | ||
get("/posts_alt", params: { filters: { body: [2, 3] } }) | ||
|
||
json = JSON.parse(@response.body, object_class: OpenStruct) | ||
assert_equal [3, 2], json.map(&:priority) | ||
end | ||
|
||
test "it overrides inherited body sort with priority sort" do | ||
Post.create!(priority: 3) | ||
Post.create!(priority: 1) | ||
Post.create!(priority: 2) | ||
get("/posts_alt", params: { sort: "body" }) | ||
|
||
json = JSON.parse(@response.body, object_class: OpenStruct) | ||
assert_equal [1, 2, 3], json.map(&:priority) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class PostsAltController < PostsController | ||
filter_on :body, type: :int, internal_name: :priority | ||
sort_on :body, type: :int, internal_name: :priority | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Rails.application.routes.draw do | ||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | ||
resources :posts | ||
resources :posts_alt | ||
end |