This application allows users to upload a CSV file containing user data. Each user entry in the CSV file is validated against specific criteria before being saved to the database.
- Ruby on Rails - A web application framework written in Ruby.
- RSpec - A testing framework for Ruby.
- CSV - Ruby's built-in library for reading and writing CSV files.
- FactoryBot - A library for setting up Ruby objects as test data.
- Turbo Streams - Used for updating HTML pages in real-time.
The application's main goal is to handle CSV uploads containing user data. Each user record must include a name
and a password
that meets specific criteria to be considered valid:
- The
name
attribute is required. - The
password
attribute must:- Be between 10 and 16 characters long.
- Include at least one lowercase letter, one uppercase letter, and one digit.
- Not contain three repeating characters in a row.
Upon uploading a CSV file, the application processes each row, attempts to create a user record, and displays the result (success or failure) for each row.
The application is structured as follows:
-
Controllers:
UsersController
: Handles CSV file uploads and displays results.
-
Models:
User
: Represents a user with validations forname
andpassword
.
-
Services:
Imports::UploadCsv
: Responsible for parsing and validating CSV data, creatingUser
records, and handling exceptions for invalid CSV files.
-
Views:
- Minimal views are used, primarily to display results after CSV upload.
To run tests for the application:
-
Install Dependencies: Make sure all dependencies specified in the
Gemfile
are installed by running:bundle install
-
Run RSpec Tests: Execute the following command to run the RSpec tests located in the
spec
directory:rspec
This command will run all tests and display the results in your terminal.
To run and try out the application locally, follow these steps:
-
Clone the Repository: Clone the Git repository to your local machine:
git clone <repository-url> cd <repository-name>
-
Install Dependencies: Install all dependencies specified in the
Gemfile
:bundle install
-
Setup Database: If necessary, setup your database with:
rails db:create rails db:migrate
-
Start the Rails Server: Start the Rails server to run the application locally:
rails server
-
Access the Application: Open your web browser and navigate to
http://localhost:3000
to access the application. -
Upload CSV File: On the homepage, you can upload a CSV file containing user data following the specified format.
-
View Results: After uploading the CSV file, the application will display the results (success or failure) for each row processed.
Contributions are welcome! Feel free to fork the repository, create pull requests, and suggest improvements.
This project is licensed under the MIT License.