Skip to content

Commit

Permalink
chore: Removed request spec, Adding controller spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeoleynik committed Sep 24, 2019
1 parent 9208046 commit 4ec087e
Show file tree
Hide file tree
Showing 35 changed files with 2,770 additions and 387 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
# Ignore master key for decrypting credentials and more.
/config/master.key
/config/database.yml
/.yardoc
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This section provides quick start guide.
### Prerequisites

- [Ruby](https://www.ruby-lang.org/en/): 2.6.3
- [Ruby on Rails](https://rubyonrails.org/): 2.6.3
- [Ruby on Rails](https://rubyonrails.org/): 5.2.3
- [PostgreSQL](https://www.postgresql.org/) 9.4 or higher.

### Standard Installation
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create
def update
task = Task.find(params[:id])

if task.update_attributes(task_params)
if task.update(task_params)
render_success(TaskSerializer.new(task))
else
respond_with_errors(task)
Expand Down
18 changes: 12 additions & 6 deletions app/forms/create_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,32 @@ class CreateTask
def save
if valid?
task = Task.create!(title: title, body: body, difficulty: difficulty)
task.create_picture(image: picture_attributes[:image]) if picture_attributes.present?
create_nodes(task.id) if nodes_attributes.present?
create_user_task(task.id) if user_tasks_attributes.present?
create_association_for(task)
TaskSerializer.new(task)
else
{ errors: ErrorSerializer.serialize(self) }
end
end

# Return status 200 when task valid or 422 when not valid
def status
@status = valid? ? :ok : :unprocessable_entity
end

private

# Creates associate for Task
def create_association_for(task)
task.create_picture(image: picture_attributes[:image]) if picture_attributes.present?
create_nodes(task.id) if nodes_attributes.present?
create_user_tasks(task.id) if user_tasks_attributes.present?
end

# Creates associate with User
def create_user_task(task_id)
def create_user_tasks(task_id)
user_tasks_attributes.each do |attribute|
user_id = attribute['user_id']
UserTask.create(user_id: user_id, task_id: task_id)
UserTask.create!(user_id: user_id, task_id: task_id)
TaskMailer.with(user: user_id, task: task_id).create_task.deliver_later
end
end
Expand All @@ -44,7 +50,7 @@ def create_user_task(task_id)
def create_nodes(task_id)
nodes_attributes.each do |attribute|
theme_id = attribute['theme_id']
Node.create(theme_id: theme_id, task_id: task_id)
Node.create!(theme_id: theme_id, task_id: task_id)
end
end
end
2 changes: 1 addition & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.delivery_method = :test

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
Expand Down
Loading

0 comments on commit 4ec087e

Please sign in to comment.