add rspec messages#2
add rspec messages#2RamonHossein wants to merge 1 commit intoshinosakarb:masterfrom RamonHossein:part-one
Conversation
chimame
left a comment
There was a problem hiding this comment.
I do not think we need to change Gemfile.
| # gem 'bcrypt', '~> 3.1.7' | ||
|
|
||
| # a library for generating fake data. | ||
| gem 'faker' |
There was a problem hiding this comment.
It is desirable to be in the test group.
There was a problem hiding this comment.
I would like use gem faker to generate data at random in db/seeds.rb.
There was a problem hiding this comment.
If so, should you limit it with development and test? We do not need it for staging or production.
| # database cleaner | ||
| gem 'database_rewinder' | ||
| # a library for setting up Ruby objects as test data. | ||
| gem 'factory_girl_rails', '~> 4.0' |
There was a problem hiding this comment.
Why did you add version designation?
There was a problem hiding this comment.
Habit, I wouldn't like to be problem with oldest versions.
There was a problem hiding this comment.
I specified the lowest version in Gemfile.lock. I am worried about inhibiting version up by writing this.
| # shoulda-matcher provides Rspec and Minitest compatible one liners that test common Rails functionality. | ||
| gem 'shoulda-matchers', '~> 3.1' | ||
| # strategies for cleaning database in Ruby. | ||
| gem 'database_cleaner' |
There was a problem hiding this comment.
There is no need to change from database_rewinder.
| # strategies for cleaning database in Ruby. | ||
| gem 'database_cleaner' | ||
| # an IRB alternative and runtime developer console. | ||
| gem 'pry' |
There was a problem hiding this comment.
You should add it to development and test if necessary.
| # json genarator | ||
| gem 'active_model_serializers' | ||
| # ActiveModel::Serializer implementation and Rails hooks. | ||
| gem 'active_model_serializers', '~> 0.10.0' |
There was a problem hiding this comment.
Why did you add version designation?
There was a problem hiding this comment.
Habit, I wouldn't like to be problem with oldest versions.
There was a problem hiding this comment.
I specified the lowest version in Gemfile.lock. I am worried about inhibiting version up by writing this.
| end | ||
|
|
||
| # PATCH/PUT /messages/1 | ||
| # PUT / messages / :id |
There was a problem hiding this comment.
It should be patch. Please check bin/rake routes.
| render json: @message.errors, status: :unprocessable_entity | ||
| end | ||
| @message.update(message_params) | ||
| head :no_content |
There was a problem hiding this comment.
What is the reason for changing?
There was a problem hiding this comment.
This is the expected behavior in case of a DELETE and UPDATE request, because if you are actually not sending any content, it is best to mention it with a :no_content.
| # DELETE / messages / :id | ||
| def destroy | ||
| @message.destroy | ||
| head :no_content |
There was a problem hiding this comment.
This is the expected behavior in case of a DELETE and UPDATE request, because if you are actually not sending any content, it is best to mention it with a :no_content.
| # Only allow a trusted parameter "white list" through. | ||
| def message_params | ||
| params.require(:message).permit(:text) | ||
| params.permit(:text) |
There was a problem hiding this comment.
What is the reason for changing?
|
|
||
| included do | ||
| rescue_from ActiveRecord::RecordNotFound do |e| | ||
| json_response({ message: e.message }, :not_found) |
There was a problem hiding this comment.
Since modules are not loosely coupled, it is not recommended to do such a construction.
There was a problem hiding this comment.
Since browsers only read 4xx & 5xx error codes, all Rails exceptions have to be inferred. Thus, ExceptionHandler simply has to manage how the 4xx / 5xx errors are passed to the browser and it provides the more graceful included method.
Created rspec model
Message.Created rspec controller
Message.Created a helper method
jsonwhich parses the JSON response to a ruby hash.Created a method
json_responsethat responds with JSON and an HTTP status code (200 by default).In
exception_handlerwe'll rescue from the exceptions and return a message.