Skip to content

Commit a734f1d

Browse files
committed
User/Project/Ticket factories, spec for TicketTimer
1 parent 98dc171 commit a734f1d

File tree

8 files changed

+60
-2
lines changed

8 files changed

+60
-2
lines changed

app/models/ticket_timer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class TicketTimer < ActiveRecord::Base
44
belongs_to :ticket
55
has_one :project, through: :ticket
66

7-
scope :created_by, lambda { |user| where admin_user_id: user.id }
7+
scope :created_by, ->(u) { where admin_user_id: u.id }
88

99
def elapsed_time
1010
Time.zone.now - created_at.to_time

config/environments/test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# The :test delivery method accumulates sent emails in the
2929
# ActionMailer::Base.deliveries array.
3030
config.action_mailer.delivery_method = :test
31+
config.action_mailer.default_url_options = { :host => 'sprintapp.test' }
3132

3233
# Use SQL instead of Active Record's schema dumper when creating the test database.
3334
# This is necessary if your schema can't be completely dumped by the schema dumper,

spec/factories/admin_users.rb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FactoryGirl.define do
2+
factory :admin_user do
3+
first_name { Faker::Name.first_name }
4+
last_name { Faker::Name.last_name }
5+
sequence(:email) { |n| "user#{n}@example.com" }
6+
password 'password'
7+
password_confirmation 'password'
8+
role { 'admin' }
9+
10+
factory :employee do
11+
role { 'employee' }
12+
end
13+
end
14+
end

spec/factories/projects.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FactoryGirl.define do
2+
factory :project do
3+
association :client
4+
association :product_owner, factory: :admin_user
5+
sequence(:name) { |n| "Project #{n}" }
6+
start_date { Date.today }
7+
members { [create(:employee)] }
8+
end
9+
end

spec/factories/ticket_priorities.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FactoryGirl.define do
22
factory :ticket_priority do
33
sequence(:name) { |n| "Priority: #{n}"}
4-
weight { :normal }
4+
weight { 'normal' }
55
end
66
end

spec/factories/ticket_timers.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FactoryGirl.define do
2+
factory :ticket_timer do
3+
ticket
4+
admin_user
5+
end
6+
end

spec/factories/tickets.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FactoryGirl.define do
2+
factory :ticket do
3+
project
4+
ticket_priority
5+
ticket_category
6+
association :status, factory: :ticket_status
7+
8+
sequence(:name) { |n| "Ticket #{n}" }
9+
description { Faker::Lorem.paragraph }
10+
end
11+
end

spec/models/ticket_timer_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'spec_helper'
2+
3+
describe TicketTimer do
4+
5+
it { should belong_to :admin_user }
6+
it { should belong_to :ticket }
7+
it { should have_one(:project).through(:ticket) }
8+
9+
describe '#created_by' do
10+
subject(:timer) { create(:ticket_timer) }
11+
12+
it 'should find timers belonging to this user' do
13+
TicketTimer.created_by(timer.admin_user).should include(timer)
14+
end
15+
end
16+
17+
end

0 commit comments

Comments
 (0)