-schema_class
=>
'Schema::Create'
;
{
ok
my
$person
= Schema
->resultset(
'Person'
)
->create({
username
=>
' jjn '
,
first_name
=>
'john'
,
last_name
=>
'napiorkowski'
,
password
=>
'hello'
,
}),
'created fixture'
;
ok
$person
->invalid,
'attempted record invalid'
;
ok !
$person
->in_storage,
'record was not saved'
;
is_deeply +{
$person
->errors->to_hash(
full_messages
=>1)}, +{
password
=> [
"Password is too short (minimum is 8 characters)"
,
],
password_confirmation
=> [
"Password Confirmation doesn't match 'Password'"
,
],
},
'Got expected errors'
;
$person
->password(
'thisislongenough'
);
$person
->insert;
ok
$person
->invalid,
'attempted record invalid'
;
ok !
$person
->in_storage,
'record was not saved'
;
is_deeply +{
$person
->errors->to_hash(
full_messages
=>1)}, +{
password_confirmation
=> [
"Password Confirmation doesn't match 'Password'"
,
],
},
'Got expected errors'
;
$person
->password(
'thisislongenough2'
);
$person
->password_confirmation(
'thisislongenough2'
);
$person
->insert;
ok
$person
->valid,
'valid record'
;
ok
$person
->in_storage,
'record was saved'
;
is
$person
->username,
'jjn'
,
'username got trim filter applied'
;
$person
->last_name(
'nap'
);
$person
->update;
ok
$person
->valid,
'valid record'
;
ok
$person
->in_storage,
'record was saved'
;
$person
->password(
'thisislongenough3'
);
$person
->update;
ok
$person
->invalid,
'attempted record invalid'
;
ok
$person
->in_storage,
'record still in storage'
;
ok
$person
->is_changed;
is_deeply +{
$person
->errors->to_hash(
full_messages
=>1)}, +{
password_confirmation
=> [
"Password Confirmation doesn't match 'Password'"
,
],
},
'Got expected errors'
;
$person
->password_confirmation(
'thisislongenough3'
);
$person
->update;
ok
$person
->valid,
'valid record'
;
my
$profile
=
$person
->create_related(
'profile'
, {
});
ok
$profile
->invalid,
'invalid record'
;
ok !
$profile
->in_storage,
'record wasnt saved'
;
is_deeply +{
$profile
->errors->to_hash(
full_messages
=>1)}, +{
"address"
,
[
"Address can't be blank"
,
"Address is too short (minimum is 2 characters)"
,
],
"city"
,
[
"City can't be blank"
,
"City is too short (minimum is 2 characters)"
,
],
"birthday"
,
[
"Birthday doesn't look like a date"
,
],
"zip"
,
[
"Zip can't be blank"
,
"Zip is not a zip code"
,
],
},
'Got expected errors'
;
$profile
->address(
'15604 Harry Lind Road'
);
$profile
->city(
'Elgin'
);
$profile
->zip(
'78621'
);
$profile
->birthday(DateTime->now->subtract(
years
=>20)->ymd);
$profile
->update_or_insert;
ok
$profile
->valid,
'valid record'
;
ok
$profile
->in_storage,
'record was saved'
;
}
{
my
$person
= Schema
->resultset(
'Person'
)
->create({
username
=>
' jjn '
,
first_name
=>
'john'
,
last_name
=>
'napiorkowski'
,
password
=>
'hellohello'
,
password_confirmation
=>
'hellohello'
,
});
ok
$person
->invalid,
'attempted record invalid'
;
ok !
$person
->in_storage,
'record was not saved'
;
is_deeply +{
$person
->errors->to_hash(
full_messages
=>1)}, +{
username
=> [
'Username chosen is not unique'
,
],
},
'Got expected errors'
;
$person
->username(
'jjn2'
);
$person
->insert;
ok
$person
->valid,
'valid record'
;
ok
$person
->in_storage,
'record was saved'
;
$person
->username(
'jjn'
);
$person
->update;
ok
$person
->invalid,
'attempted record invalid'
;
is_deeply +{
$person
->errors->to_hash(
full_messages
=>1)}, +{
username
=> [
'Username chosen is not unique'
,
],
},
'Got expected errors'
;
}
{
ok
my
$person
= Schema
->resultset(
'Person'
)
->find({
username
=>
'jjn'
});
$person
->first_name(
'j'
);
$person
->update;
is_deeply +{
$person
->errors->to_hash(
full_messages
=>1)}, +{
first_name
=> [
'First Name is too short (minimum is 2 characters)'
,
],
},
'Got expected errors'
;
$person
->first_name(
'jon'
);
$person
->password(
'abc'
);
$person
->update;
is_deeply +{
$person
->errors->to_hash(
full_messages
=>1)}, +{
password
=> [
"Password is too short (minimum is 8 characters)"
,
],
password_confirmation
=> [
"Password Confirmation doesn't match 'Password'"
,
],
},
'Got expected errors'
;
$person
->password(
'abc124efg'
);
$person
->password_confirmation(
'abc124efg'
);
$person
->update;
ok
$person
->valid,
'valid record'
;
$person
->last_name(
'n'
);
$person
->profile->zip(
'sadsdasdasdasdsdfsdfsdfsdf'
);
$person
->update;
ok
$person
->invalid;
is_deeply +{
$person
->errors->to_hash(
full_messages
=>1)}, +{
"last_name"
,
[
"Last Name is too short (minimum is 2 characters)"
,
],
"profile"
,
[
"Profile Is Invalid"
,
],
"profile.zip"
,
[
"Profile Zip is not a zip code"
,
],
},
'Got expected errors'
;
is_deeply +{
$person
->profile->errors->to_hash(
full_messages
=>1)}, +{
"zip"
,
[
"Zip is not a zip code"
,
],
},
'Got expected errors'
;
$person
->update({
last_name
=>
'longenough'
,
profile
=> {
zip
=>
'12345'
,
}
});
ok
$person
->valid;
}
{
ok
my
$person
= Schema
->resultset(
'Person'
)
->create({
username
=>
' jjn3 '
,
first_name
=>
'john'
,
last_name
=>
'napiorkowski'
,
password
=>
'hellohello'
,
password_confirmation
=>
'hellohello'
,
}),
'created fixture'
;
ok
$person
->valid,
'attempted record valid'
;
ok
$person
->in_storage,
'record was saved'
;
is
$person
->username,
'jjn3'
;
{
ok
my
$person
= Schema->resultset(
'Person'
)->find({
username
=>
'jjn3'
});
$person
->update({
last_name
=>
'n'
,
profile
=> {
zip
=>
'12345'
,
city
=>
'Elgin'
,
birthday
=>
'2011-01-01'
,
}
});
ok
$person
->invalid;
ok !
$person
->profile->in_storage;
is
$person
->last_name,
'n'
;
is
$person
->profile->zip,
'12345'
;
is
$person
->profile->city,
'Elgin'
;
is
$person
->profile->birthday->ymd,
'2011-01-01'
;
is_deeply +{
$person
->errors->to_hash(
full_messages
=>1)}, +{
"profile.address"
,
[
"Profile Address can't be blank"
,
"Profile Address is too short (minimum is 2 characters)"
,
],
"profile"
,
[
"Profile Is Invalid"
,
],
"last_name"
,
[
"Last Name is too short (minimum is 2 characters)"
,
],
},
'Got expected errors'
;
$person
->update({
last_name
=>
'nnnnnnnnnnnnnn'
,
profile
=> {
address
=>
'12345 Home Way'
,
}
});
ok
$person
->valid;
ok
$person
->profile->in_storage;
is
$person
->last_name,
'nnnnnnnnnnnnnn'
;
is
$person
->profile->address,
'12345 Home Way'
;
{
ok
my
$person
= Schema->resultset(
'Person'
)->find({
username
=>
'jjn3'
});
is
$person
->last_name,
'nnnnnnnnnnnnnn'
;
is
$person
->profile->address,
'12345 Home Way'
;
}
}
}
{
ok
my
$person
= Schema
->resultset(
'Person'
)
->find_or_create({
username
=>
' jjn4 '
,
first_name
=>
'john'
,
last_name
=>
'napiorkowski'
,
}),
'created fixture'
;
ok
$person
->invalid;
ok !
$person
->in_storage;
is_deeply +{
$person
->errors->to_hash(
full_messages
=>1)}, +{
password
=> [
"Password can't be blank"
,
"Password is too short (minimum is 8 characters)"
,
],
},
'Got expected errors'
;
}
{
ok
my
$person
= Schema
->resultset(
'Person'
)
->update_or_create({
username
=>
' jjn4 '
,
first_name
=>
'john'
,
last_name
=>
'napiorkowski'
,
}),
'created fixture'
;
ok
$person
->invalid;
ok !
$person
->in_storage;
is_deeply +{
$person
->errors->to_hash(
full_messages
=>1)}, +{
password
=> [
"Password can't be blank"
,
"Password is too short (minimum is 8 characters)"
,
],
},
'Got expected errors'
;
}
{
ok
my
$person
= Schema
->resultset(
'Person'
)
->update_or_create({
username
=>
'jjn3'
,
first_name
=>
'j'
,
}),
'created fixture'
;
ok
$person
->invalid;
ok
$person
->is_changed;
is_deeply +{
$person
->errors->to_hash(
full_messages
=>1)}, +{
"first_name"
, [
"First Name is too short (minimum is 2 characters)"
,
],
},
'Got expected errors'
;
}
{
ok
my
$person
= Schema
->resultset(
'Person'
)
->find({
username
=>
'jjn3'
});
$person
->update({
username
=>
'jjn3'
,
first_name
=>
'j'
,
profile
=> {
zip
=>
'asfdsadfsafasdfsdf'
}
});
ok
$person
->invalid;
ok
$person
->is_changed;
is_deeply +{
$person
->errors->to_hash(
full_messages
=>1)}, +{
"first_name"
, [
"First Name is too short (minimum is 2 characters)"
,
],
"profile"
, [
"Profile Is Invalid"
,
],
"profile.zip"
, [
"Profile Zip is not a zip code"
,
],
},
'Got expected errors'
;
}
{
ok
my
$person
= Schema
->resultset(
'Person'
)
->update_or_create({
username
=>
'jjn3'
,
first_name
=>
'j'
,
profile
=> {
zip
=>
'asfdsadfsafasdfsdf'
}
}),
'created fixture update_or_create'
;
ok
$person
->invalid;
ok
$person
->is_changed;
is_deeply +{
$person
->errors->to_hash(
full_messages
=>1)}, +{
"first_name"
, [
"First Name is too short (minimum is 2 characters)"
,
],
"profile"
, [
"Profile Is Invalid"
,
],
"profile.zip"
, [
"Profile Zip is not a zip code"
,
],
},
'Got expected errors'
;
}
{
ok
my
$person
= Schema
->resultset(
'Person'
)
->find({
username
=>
'jjn3'
});
my
$profile
=
$person
->find_or_create_related(
'profile'
, +{});
is
$profile
->zip, 12345;
$profile
->zip(
"asdasda"
);
$person
->update;
ok
$person
->valid;
ok
$person
->profile->valid;
$profile
->update;
ok
$profile
->invalid;
ok
$person
->profile->valid;
is
$person
->profile->zip, 12345;
}
done_testing;