This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "Counting average execution time should return proper results" do | |
task_1 = Task.create(name: "ABCD", status: "Created", completion_time:30) | |
task_2 = Task.create(name: "ABCDE", status: "Created", completion_time: 70) | |
sum_of_completion_time = task_1.completion_time + task_2.completion_time | |
number_of_tasks = Task.all.count | |
average_execution_time = sum_of_completion_time / number_of_tasks | |
expect(average_execution_time).to eq(task_2.count_average_execution_time) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe Task, type: :model do | |
let(:task) {FactoryGirl.create(:task)} | |
let(:task_created_1) {FactoryGirl.create(:task_created_1)} | |
let(:task_created_2) {FactoryGirl.create(:task_created_2)} | |
let(:task_in_progress_1) {FactoryGirl.create(:task_in_progress_1)} | |
let(:task_in_progress_2) {FactoryGirl.create(:task_in_progress_2)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FactoryGirl.define do | |
factory :task do |t| | |
t.status "Created" | |
t.completion_time 10 | |
factory :task_created_1 do |t| | |
t.status "Created" | |
t.completion_time 90 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Task < ActiveRecord::Base | |
validates :status, inclusion: {in: ["Created", "In Progress", "Completed"]} | |
scope :by_status, -> (status) {where(status: status)} | |
after_create :count_average_execution_time | |
belongs_to :house_hold | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe Task, type: :model do | |
let(:task2) {FactoryGirl.create(:task2)} | |
let(:task) {FactoryGirl.create(:task)} | |
let(:task_not_valid) {FactoryGirl.create(:task_not_valid, status: "Not valid")} | |
it "Task with not valid status should not be saved" do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FactoryGirl.define do | |
factory :task do |t| | |
t.status "Created" | |
t.completion_time 10 | |
end | |
factory :task_two do |t| | |
t.status "Created" | |
t.completion_time 20 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Comments</h2> | |
<% comments.each do |comment| %> | |
<p><%= comment.content %> <%= link_to "Usuń", [@commentable, comment], method: :delete %></p> | |
<% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CommentsController < ApplicationController | |
before_action :load_commentable, only: [:create, :index, :destroy] | |
before_action :find_comment, only: [:destroy] | |
def create | |
@comment = @commentable.comments.new(comment_params) | |
if @comment.save | |
redirect_to @commentable | |
end | |
end |