The previous blog introduced some knowledge about rails testing. Test the location of the files, the types of tests, test common commands, and some of the resources available, and how to generate mock data using fixtures.
Today we're going to actually write unit tests, and the knowledge we use is mainly fixtures and test. Fixtures is used to simulate data, unit test is our leading actor today.
Today's code will write some unit tests for this project in the context of a blog project.
The code for this project is available in Https://github.com/woaigithub/blog, and the project has been deployed to http://42.121.5.68:10000/, and you can write your own blog directly on the deployed production environment.
Master is the main branch, develop is the development branch, and the code in the Development branch is up to date.
The project uses Ruby on Rails to develop, develop, and test the environment using SQLITE3 as the data store, and the production environment uses MySQL as the data store.
Unit Test
The Rails unit tests are focused on Model,model as our business entity. Unit Test main test model validates, as well as model business rules, testing through the implementation of business rules, our model changes, is the model of the property value, whether the description of the rules, whether to become the expected value.
= = Advertising Start
This blog is positioned as a collaborative blogging platform. Is that everyone can write a blog, blog management, including classification, tag and so on.
The main target audience for the blog is the developer, and more other types of practitioners are welcome to blog on this platform.
By registering in the upper-right corner, you can become an admin of this blog platform, and then you can write blogs and manage blogs. Of course, look at the blog is not required to register, directly can browse.
In the footer section, there is an admin link that can be entered backstage through a link. Of course, entering the background requires login.
Blog platform is still in development, if you have any good ideas, or want to join the development, can be https://github.com/woaigithub/blog on the message.
= = End of advertisement
Our project this time is a blog with some basic features.
Browse the Blogs list, sort through blogs, and browse through individual posts.
Check your blog post and leave a message for your blog.
Registered users, landing platform.
Manage blogs, manage blog posts, manage categories, manage tag, manage reviews.
Table structure is as follows
### users
Id
Nickname
Email
Password_digest
Salt
Created_at
Updated_at
### tags
Id
Title
Created_at
Updated_at
### Categorys
Id
Title
Created_at
Updated_at
### comments
Id
Commenter
Commenter_email
Commenter_url
Content
post_id
Created_at
Updated_at
### posts
Id
Title
Slug
category_id
Summary
Content
Created_at
Updated_at
user_id
### Posts_tags
post_id
tag_id