Skip to content

Instantly share code, notes, and snippets.

@egoholic
Last active August 29, 2015 14:06
Show Gist options
  • Save egoholic/beb6270e739b30f7f3c0 to your computer and use it in GitHub Desktop.
Save egoholic/beb6270e739b30f7f3c0 to your computer and use it in GitHub Desktop.
wires_json.rb
# 1. Wire is created
{
draft_wire: {
id: 1,
wire_id: '',
make: '',
model: '',
type: ''
color: ''
room_1_id: '',
room_1_description: '',
location_1_id: '',
location_1_description: '',
port_1_id: '',
room_2_id: '',
room_2_description: '',
location_2_id: '',
location_2_description: '',
port_2_id: '',
notes: '',
actual_length: 1,
wire: {
id: 1,
color: '',
notes: '',
created_at: '',
updated_at: '',
signal_name_id: '',
room_1_id 1,
room_2_id 1,
wire_id: ''
make: '',
model: '',
wire_type: '',
actual_length: 1
},
messages: [
{
code: 0,
message: 'Wire is created!'
}
]
}
}
# 2. Wire is already exist with the same attributes
{
draft_wire: {
id: 1,
wire_id: '',
make: '',
model: '',
type: ''
color: ''
room_1_id: '',
room_1_description: '',
location_1_id: '',
location_1_description: '',
port_1_id: '',
room_2_id: '',
room_2_description: '',
location_2_id: '',
location_2_description: '',
port_2_id: '',
notes: '',
actual_length: 1
wire: {
id: 1,
color: '',
notes: '',
created_at: '',
updated_at: '',
signal_name_id: '',
room_1_id 1,
room_2_id 1,
wire_id: ''
make: '',
model: '',
wire_type: '',
actual_length: 1
},
messages: [
{
code: 1,
message: 'Wire is already exist with the same attributes!'
}
]
}
}
# 3. Wire attributes are mismatch
{
draft_wire: {
id: 1,
wire_id: '',
make: '',
model: '',
type: ''
color: ''
room_1_id: '',
room_1_description: '',
location_1_id: '',
location_1_description: '',
port_1_id: '',
room_2_id: '',
room_2_description: '',
location_2_id: '',
location_2_description: '',
port_2_id: '',
notes: '',
actual_length: 1,
wire: {
id: 1,
color: '',
notes: '',
created_at: '',
updated_at: '',
signal_name_id: '',
room_1_id 1,
room_2_id 1,
wire_id: ''
make: '',
model: '',
wire_type: '',
actual_length: 1
},
errors: {
make: [
{
code: 4,
message: ''
}
]
}
}
}
# 4. Room attributes are mismatch
{
draft_wire: {
id: 1,
wire_id: '',
make: '',
model: '',
type: ''
color: ''
room_1_id: '',
room_1_description: '',
location_1_id: '',
location_1_description: '',
port_1_id: '',
room_2_id: '',
room_2_description: '',
location_2_id: '',
location_2_description: '',
port_2_id: '',
notes: '',
actual_length: 1,
errors: {
room_2_description: [
{
code: 4
message: ''
}
]
}
}
}
# 5. Location attributes are mismatch
{
draft_wire: {
id: 1,
wire_id: '',
make: '',
model: '',
type: ''
color: ''
room_1_id: '',
room_1_description: '',
location_1_id: '',
location_1_description: '',
port_1_id: '',
room_2_id: '',
room_2_description: '',
location_2_id: '',
location_2_description: '',
port_2_id: '',
notes: '',
actual_length: 1,
errors: {
location_2_description: [
{
code: 4,
message: ''
}
]
}
},
}
# 6. Room does not exist
{
draft_wire: {
id: 1,
wire_id: '',
make: '',
model: '',
type: ''
color: ''
room_1_id: '',
room_1_description: '',
location_1_id: '',
location_1_description: '',
port_1_id: '',
room_2_id: '',
room_2_description: '',
location_2_id: '',
location_2_description: '',
port_2_id: '',
notes: '',
actual_length: 1,
errors: {
room_id: [
{
code: 5,
message: 'Room does not exist!'
}
]
}
}
}
# 7. Location does not exist
{
draft_wire: {
id: 1,
wire_id: '',
make: '',
model: '',
type: ''
color: ''
room_1_id: '',
room_1_description: '',
location_1_id: '',
location_1_description: '',
port_1_id: '',
room_2_id: '',
room_2_description: '',
location_2_id: '',
location_2_description: '',
port_2_id: '',
notes: '',
actual_length: 1,
errors: {
room_2_id: [
{
code: 5,
message: 'Location does not exist!'
}
]
}
}
}
# error message codes:
# 1- can't be blank
# 2- not unique
# 3- invalid format / not integer / greater or less
# 4- attribute is mismatch
# 5- association does not exist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment