diff --git a/README.md b/README.md index 024a485..d3f209f 100644 --- a/README.md +++ b/README.md @@ -3,5 +3,43 @@ ## Project Setup ```sh -rails new -T -d sqlite3 scheduled_reminders +rails db:create db:migrate ``` + +## Running the tests + +```sh +rspec +``` + +## Running app + +```sh +rails s +``` + +## System dependencies + +- sendmail + +## Task + +> In order to get some insight into your coding style and approach to problem solving, we would like to give you a small programming task for you to solve. You can either upload the project to Github or send it to us via mail. It’s not supposed to win any beauty contest either, so it doesn’t really matter how the views look, as long as the functionality is there. +> +> Ideally you create an initial commit after the invocation of`rails new`, so it’s easy to blank out the skeleton code. +> +> Here it goes: +> Sample Task: Scheduled Reminders +> Description: write an application that sends scheduled reminders to its users. +> +> Functionality: +> - a user can register with email and password +> - after signing in, they see a list of existing reminders and can set up new ones +> - once a month, on a configurable day and time, the application sends them an email with the reminder title and text +> - existing reminders can be deleted from the list +> Configuration of the reminder: +> - title +> - description / text +> - day and time of month. Should be any possible day of the month. I.e. “1st of month”, “2nd of month”, but also “last of month”, “2nd last month” +> +> Ideally, tests should be in place, too. If you have any questions, feel free to ask. diff --git a/app/controllers/reminders_controller.rb b/app/controllers/reminders_controller.rb index 4aa60e5..35ce2ac 100644 --- a/app/controllers/reminders_controller.rb +++ b/app/controllers/reminders_controller.rb @@ -19,6 +19,7 @@ class RemindersController < ApplicationController if @reminder.save redirect_to @reminder, notice: 'Reminder was successfully created.' + set_email_schedule else render :new end @@ -27,6 +28,7 @@ class RemindersController < ApplicationController def update if @reminder.update(reminder_params) redirect_to @reminder, notice: 'Reminder was successfully updated.' + set_email_schedule else render :edit end @@ -48,4 +50,8 @@ class RemindersController < ApplicationController def reminder_params params.require(:reminder).permit(:title, :body, :date, :user_id) end + + def set_email_schedule + ReminderMailer.schedule_email(@reminder, current_user.email).deliver_later!(wait_until: @reminder.date) + end end diff --git a/app/mailers/reminder_mailer.rb b/app/mailers/reminder_mailer.rb new file mode 100644 index 0000000..f9b342d --- /dev/null +++ b/app/mailers/reminder_mailer.rb @@ -0,0 +1,6 @@ +class ReminderMailer < ApplicationMailer + def schedule_email(reminder, recipient) + @reminder = reminder + mail to: recipient, subject: 'Reminder' + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index cd695e2..b1060e0 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,10 +11,12 @@
<%= yield %> +<%= notice %>
+<%= alert %>
<%= link_to('Logout', destroy_user_session_path) %>
+<%= link_to('Logout', destroy_user_session_path, method: 'delete') %>
<% end %>