-
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.
Merge pull request #65 from javierav/feature/country-model
Add Country model
- Loading branch information
Showing
5 changed files
with
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Country < ApplicationRecord | ||
validates :code, presence: true, uniqueness: true | ||
validates :name, presence: true | ||
validates :p1_name, presence: true | ||
validates :p2_name, presence: true | ||
validates :p3_name, presence: true | ||
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,13 @@ | ||
class CreateCountries < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :countries do |t| | ||
t.timestamps null: false | ||
t.string :code, null: false | ||
t.string :name, null: false | ||
t.string :p1_name, null: false | ||
t.string :p2_name, null: false | ||
t.string :p3_name, null: false | ||
t.index :code, unique: true | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 @@ | ||
spain: | ||
id: 1 | ||
code: "ES" | ||
name: "España" | ||
p1_name: "Punta" | ||
p2_name: "Llano" | ||
p3_name: "Valle" |
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,51 @@ | ||
require "test_helper" | ||
|
||
class CountryTest < ActiveSupport::TestCase | ||
test "create without code" do | ||
country = Country.new | ||
|
||
assert_not country.save | ||
assert country.errors.added?(:code, :blank) | ||
end | ||
|
||
test "create without name" do | ||
country = Country.new | ||
|
||
assert_not country.save | ||
assert country.errors.added?(:name, :blank) | ||
end | ||
|
||
test "create without p1_name" do | ||
country = Country.new | ||
|
||
assert_not country.save | ||
assert country.errors.added?(:p1_name, :blank) | ||
end | ||
|
||
test "create without p2_name" do | ||
country = Country.new | ||
|
||
assert_not country.save | ||
assert country.errors.added?(:p2_name, :blank) | ||
end | ||
|
||
test "create without p3_name" do | ||
country = Country.new | ||
|
||
assert_not country.save | ||
assert country.errors.added?(:p3_name, :blank) | ||
end | ||
|
||
test "create with duplicate code" do | ||
country = Country.new(code: "ES") | ||
|
||
assert_not country.save | ||
assert country.errors.added?(:code, :taken, value: "ES") | ||
end | ||
|
||
test "create with valid attributes" do | ||
country = Country.new(code: "UK", name: "United Kingdom", p1_name: "On-Peak", p2_name: "Standard", p3_name: "Off-Peak") | ||
|
||
assert country.save | ||
end | ||
end |