-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e59ef2b
commit 6757c92
Showing
8 changed files
with
74 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "test_helper" | ||
|
||
class Api::PokemonsControllerTest < ActionDispatch::IntegrationTest | ||
def setup | ||
create(:pokemon) | ||
create(:pokemon) | ||
end | ||
|
||
test "index responds successfully" do | ||
get api_pokemons_path | ||
assert :success | ||
|
||
assert_routing api_pokemons_path, controller: 'api/pokemons', action: 'index' | ||
end | ||
|
||
test "index lists all pokemons" do | ||
get api_pokemons_path | ||
|
||
assert_equal JSON.parse(response.body).count, Pokemon.count | ||
end | ||
|
||
test "show responds successfully" do | ||
get api_pokemon_show_path(1) | ||
assert :success | ||
|
||
assert_routing api_pokemon_show_path(1), controller: 'api/pokemons', action: 'show', id: '1' | ||
end | ||
|
||
test "show retrieves details of one pokemon" do | ||
pokemon = Pokemon.first | ||
|
||
get api_pokemon_show_path(pokemon) | ||
|
||
assert_equal JSON.parse(response.body)["id"], pokemon.id | ||
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,16 @@ | ||
FactoryBot.define do | ||
factory :pokemon do | ||
name { Faker::Games::Pokemon.name } | ||
base_experience { Faker::Number.number(digits: 2) } | ||
height { Faker::Number.number(digits: 2) } | ||
is_default { Faker::Boolean.boolean } | ||
order { Faker::Number.number(digits: 2) } | ||
weight { Faker::Number.decimal(l_digits: 2) } | ||
|
||
after :create do |pokemon| | ||
types = FactoryBot.create_list :type, 2 | ||
pokemon.types << types | ||
pokemon.save | ||
end | ||
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,5 @@ | ||
FactoryBot.define do | ||
factory :type do | ||
name { Faker::Types.rb_string } | ||
end | ||
end |
Empty file.
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