Skip to content

Commit

Permalink
Returning full error messages in json responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
daronco committed Jun 9, 2011
1 parent 7757ada commit 55bc7c2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/controllers/bigbluebutton/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def create
render :action => "new"
end
}
format.json { render :json => @room.errors, :status => :unprocessable_entity }
format.json { render :json => @room.errors.full_messages, :status => :unprocessable_entity }
end
end
end
Expand Down Expand Up @@ -80,7 +80,7 @@ def update
render :action => "edit"
end
}
format.json { render :json => @room.errors, :status => :unprocessable_entity }
format.json { render :json => @room.errors.full_messages, :status => :unprocessable_entity }
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/bigbluebutton/servers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def create
format.json { render :json => @server, :status => :created }
else
format.html { render :action => "new" }
format.json { render :json => @server.errors, :status => :unprocessable_entity }
format.json { render :json => @server.errors.full_messages, :status => :unprocessable_entity }
end
end
end
Expand All @@ -48,7 +48,7 @@ def update
format.json { head :ok }
else
format.html { render :action => "edit" }
format.json { render :json => @server.errors, :status => :unprocessable_entity }
format.json { render :json => @server.errors.full_messages, :status => :unprocessable_entity }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/bigbluebutton_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BigbluebuttonServer < ActiveRecord::Base

validates :url, :presence => true, :uniqueness => true, :length => { :maximum => 500 }
validates :url, :format => { :with => /http:\/\/.*\/bigbluebutton\/api/,
:message => 'URL should have the pattern http://<server>/bigbluebutton/api' }
:message => I18n.t('bigbluebutton_rails.servers.errors.url_format') }

validates :salt, :presence => true, :length => { :minimum => 1, :maximum => 500 }

Expand Down
4 changes: 3 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ en:
success: "Your server was successfully created."
update:
success: "Your server was successfully updated."
errors:
url_format: 'should use the pattern http://<server>/bigbluebutton/api'
rooms:
notice:
create:
Expand All @@ -27,7 +29,7 @@ en:
models:
bigbluebutton_server: "BigBlueButton Server"
bigbluebutton_room: "BigBlueButton Room"
attributes:
attributes:
bigbluebutton_server:
name: "Name"
url: "URL"
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/bigbluebutton/rooms_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def build_running_json(value, error=nil)
it { should respond_with_content_type(:json) }
it {
new_room.save # should fail
should respond_with_json(new_room.errors.to_json)
should respond_with_json(new_room.errors.full_messages.to_json)
}
end
end
Expand All @@ -753,7 +753,7 @@ def build_running_json(value, error=nil)
it { should respond_with_content_type(:json) }
it {
new_room.save # should fail
should respond_with_json(new_room.errors.to_json)
should respond_with_json(new_room.errors.full_messages.to_json)
}
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/bigbluebutton/servers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
it { should respond_with_content_type(:json) }
it {
new_server.save # should fail
should respond_with_json(new_server.errors.to_json)
should respond_with_json(new_server.errors.full_messages.to_json)
}
end
end
Expand All @@ -149,7 +149,7 @@
it { should respond_with_content_type(:json) }
it {
new_server.save # should fail
should respond_with_json(new_server.errors.to_json)
should respond_with_json(new_server.errors.full_messages.to_json)
}
end
end
Expand Down

0 comments on commit 55bc7c2

Please sign in to comment.