Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added age method and can drink check. #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 213 additions & 0 deletions models/human.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,218 @@ def job_title=(value)
def job_title
@job_title
end

attr_accessor :age

# def age=(value)
# @age = value
# end
#
# def age
# @age
# end

def can_drink? (country = "Australia")
@age >= AGES[country]
end
end


AGES = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great foresight here... Only small suggestion, this would be better to put in another file (or in Rails we would of had it in a DB table) to reduce the noise in the model
In this case it might be better to make this another class that you can ask for drinking_ages (as per comment below in specs). We can discuss this further next week

'Benin' => 0,
'Bolivia' => 0,
'Burkina Faso' => 0,
'Burundi' => 0,
'Cambodia' => 0,
'Cameroon' => 0,
'China' => 0,
'Gabon' => 0,
'Guinea-Bissau' => 0,
'Indonesia' => 0,
'Kosovo' => 0,
'Laos' => 0,
'Mali' => 0,
'Rwanda' => 0,
'Sao Tome and Principe' => 0,
'Sierra Leone' => 0,
'Solomon Islands' => 0,
'Timor-Leste' => 0,
'Togo' => 0,

'Antigua and Barbuda' => 10,
'Central African Republic' => 10,

'Austria' => 16,
'Belgium' => 16,
'Congo' => 16,
'Cyprus' => 16,
'Denmark' => 16,
'Dominica' => 16,
'Germany' => 16,
'Grenada' => 16,
'Guyana' => 16,
'Haiti' => 16,
'Liechtenstein' => 16,
'Luxembourg' => 16,
'Malta' => 16,
'Morocco' => 16,
'Netherlands' => 16,
'Portugal' => 16,
'Saint Lucia' => 16,
'Saint Vincent and the Grenadines' => 16,
'San Marino' => 16,
'Spain' => 16,
'Switzerland' => 16,

'Albania' => 18,
'Algeria' => 18,
'Andorra' => 18,
'Angola' => 18,
'Argentina' => 18,
'Armenia' => 18,
'Australia' => 18,
'Azerbaijan' => 18,
'Bahamas' => 18,
'Barbados' => 18,
'Belarus' => 18,
'Belize' => 18,
'Bhutan' => 18,
'Bosnia and Herzegovina' => 18,
'Botswana' => 18,
'Brazil' => 18,
'Bulgaria' => 18,
'Canada' => 18,
'Cape Verde' => 18,
'Chad' => 18,
'Chile' => 18,
'Colombia' => 18,
'Comoros' => 18,
'Costa Rica' => 18,
'Croatia' => 18,
'Cuba' => 18,
'Czech Republic' => 18,
'Democratic Republic of the Congo' => 18,
'Dominican Republic' => 18,
'Ecuador' => 18,
'Egypt' => 18,
'El Salvador' => 18,
'Eritrea' => 18,
'Estonia' => 18,
'Ethiopia' => 18,
'Fiji' => 18,
'Finland' => 18,
'France' => 18,
'Gambia' => 18,
'Georgia' => 18,
'Ghana' => 18,
'Greece' => 18,
'Guatemala' => 18,
'Guinea' => 18,
'Honduras' => 18,
'Hungary' => 18,
'India' => 18,
'Ireland' => 18,
'Israel' => 18,
'Italy' => 18,
'Jamaica' => 18,
'Jordan' => 18,
'Kazakhstan' => 18,
'Kenya' => 18,
'Kyrgyzstan' => 18,
'Latvia' => 18,
'Lesotho' => 18,
'Liberia' => 18,
'Lithuania' => 18,
'Macedonia' => 18,
'Madagascar' => 18,
'Malawi' => 18,
'Malaysia' => 18,
'Mauritius' => 18,
'Mexico' => 18,
'Moldova' => 18,
'Monaco' => 18,
'Montenegro' => 18,
'Mozambique' => 18,
'Myanmar' => 18,
'Namibia' => 18,
'Nepal' => 18,
'New Zealand' => 18,
'Nicaragua' => 18,
'Niger' => 18,
'Nigeria' => 18,
'Norway' => 18,
'Panama' => 18,
'Papua New Guinea' => 18,
'Peru' => 18,
'Philippines' => 18,
'Poland' => 18,
'Romania' => 18,
'Russia' => 18,
'Saint Kitts and Nevis' => 18,
'Senegal' => 18,
'Serbia' => 18,
'Seychelles' => 18,
'Singapore' => 18,
'Slovakia' => 18,
'Slovenia' => 18,
'South Africa' => 18,
'South Korea' => 18,
'Suriname' => 18,
'Swaziland' => 18,
'Sweden' => 18,
'Syria' => 18,
'Tajikistan' => 18,
'Tanzania' => 18,
'Tonga' => 18,
'Trinidad and Tobago' => 18,
'Tunisia' => 18,
'Turkey' => 18,
'Turkmenistan' => 18,
'Tuvalu' => 18,
'Uganda' => 18,
'Ukraine' => 18,
'United Kingdom' => 18,
'Uruguay' => 18,
'Vanuatu' => 18,
'Vatican City' => 18,
'Venezuela' => 18,
'Vietnam' => 18,
'Zambia' => 18,
'Zimbabwe' => 18,

'Iceland' => 20,
'Japan' => 20,
'Paraguay' => 20,
'Thailand' => 20,
'Uzbekistan' => 20,

'Côte d\'Ivoire' => 21,
'Equatorial Guinea' => 21,
'Iraq' => 21,
'Kiribati' => 21,
'Micronesia' => 21,
'Mongolia' => 21,
'Nauru' => 21,
'Oman' => 21,
'Palau' => 21,
'Samoa' => 21,
'Sri Lanka' => 21,
'United States' => 21,

'Afghanistan' => 999,
'Bahrain' => 999,
'Bangladesh' => 999,
'Brunei Darussalam' => 999,
'Iran' => 999,
'Kuwait' => 999,
'Libya' => 999,
'Maldives' => 999,
'Mauritania' => 999,
'Pakistan' => 999,
'Qatar' => 999,
'Saudi Arabia' => 999,
'Somalia' => 999,
'Sudan' => 999,
'United Arab Emirates' => 999,
'Yemen' => 999
}
40 changes: 38 additions & 2 deletions specs/models/human_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,45 @@
end
end

describe '.age=' do
it 'sets the age for our human instance' do
human = Human.new('')
expect(human).to respond_to(:age=)
end
end

describe '.age' do
it 'it returns the age' do
human = Human.new('')
human.age = 18
expect(human.age).to eq(18)
end
end

describe '.can_drink?' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work that you put all the expectations inside of one describe block

it 'returns true if human is of age' do
human = Human.new('Boris')
human.age = 35
expect(human.can_drink?).to be true
end

it 'returns false if human is underage' do
human = Human.new('Boris Jr')
human.age = 14
expect(human.can_drink?).to be false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try not to leave blank lines between the end

end

it 'checks the drinking age for a given country' do
human = Human.new('Garfield')
human.age = 18
expect(human.can_drink? 'Australia').to be true
expect(human.can_drink? 'United States').to be false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test to see what happens when we use an address that does not match one in our list

end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add another test and not set age and see what happens

end


it 'play area' do
puts Human.new('Caitlin').name
end
end