So after generating user data then we are requesting for CSV and we are expecting that test_user data should get in CSV. So while testing CSV data, first we need to make one user with the help of a factory_bot_rails gem. In the above test scenario, we are testing CSV data. There can be many fields/columns in CSV, but we are considering only a few of them.Ĭsv_first_row = CSV.parse(response.body)Įxpected_first_row = [test_user.first_name, test_user.last_name,Įxpect(expected_first_row).to match_array(csv_first_row) But sometimes we need to download specific records coming from custom queries or scope.
Let me explain how one can do the same if needed.īy default records that are being displayed on the screen are exported in CSV, XML, or JSON. Hence I added RSpec test cases around it. While discussing the same with my team, we landed on the perspective that CSV is exported via gem then should we test it or not? As my feature was a core of business logic & is related to critical flow, I thought we should test it. For that, I wanted to write Rspec test cases, as it was an important part for admins. In one of our projects, we have built a feature for CSV export in Active admin. So basically Active admin abstracts common business applications in a simple pattern so that developers can use it and implement a beautiful interface with very little effort. Usually, UI for admin users needs to be more of managing and reporting the business operations than the fancy UI which we build for end-users. Active admin is a great framework for managing website admin side interface.