Skip to content

Commit 18bceea

Browse files
authored
Merge pull request #171 from likeath/fix/specs-and-deprecations
Fix deprecations & specs
2 parents b8f4fc8 + 88e087d commit 18bceea

File tree

5 files changed

+33
-29
lines changed

5 files changed

+33
-29
lines changed

apps/admin/views/tasks/index.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class Index
33
include Admin::View
44

55
def tasks
6-
TaskRepository.new.tasks.order{ id.desc }.as(Task).to_a
6+
TaskRepository.new.tasks.order{ id.desc }.map_to(Task).to_a
77
end
88

99
def repository_name(task)

apps/admin/views/users/index.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class Index
33
include Admin::View
44

55
def users
6-
UserRepository.new.users.order{ id.desc }.as(User).to_a
6+
UserRepository.new.users.order{ id.desc }.map_to(User).to_a
77
end
88

99
def banned_users

lib/ossboard/repositories/task_repository.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def assigned_tasks_for_user(user)
3939
private
4040

4141
def all_from_date_request(from, status = nil)
42-
request = tasks.where("created_at > '#{from}'").where("created_at < '#{Time.now}'")
42+
request = tasks.where { (created_at > from) & (created_at < Time.now) }
4343
request = request.where(status: status) if status
4444
request
4545
end

lib/ossboard/repositories/user_repository.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ def all_with_points_and_tasks
4242
private
4343

4444
def all_from_date_request(from)
45-
users.where("created_at > '#{from}'").where("created_at < '#{Time.now}'")
45+
users.where { (created_at > from) & (created_at < Time.now) }
4646
end
4747
end

spec/ossboard/repositories/task_repository_spec.rb

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@
126126
end
127127

128128
describe '#all_from_date' do
129-
before(:all) do
129+
before do
130130
3.times do |i|
131131
random_days_count = i * 60 * 60 * 24
132-
Timecop.freeze(Time.new(2016, 02, 20) - random_days_count) do
132+
Timecop.freeze(Time.utc(2016, 02, 20) - random_days_count) do
133133
Fabricate.create(:task, status: 'done')
134134
Fabricate.create(:task, status: 'in progress')
135135
Fabricate.create(:task, status: 'closed')
@@ -140,35 +140,39 @@
140140
Timecop.freeze(Time.now + (2 * 60 * 60 * 24)) { Fabricate.create(:task) }
141141
end
142142

143-
describe '#all_from_date_counted_by_status_and_day' do
144-
before(:all) do
145-
3.times do |i|
146-
Timecop.freeze(Time.utc(2016, 02, 20 + i)) do
147-
Fabricate.create(:task, status: 'done')
148-
Fabricate.create(:task, status: 'in progress')
149-
Fabricate.create(:task, status: 'closed')
150-
Fabricate.create(:task, status: 'assigned')
151-
end
152-
end
153-
end
154-
155-
let (:result) { repo.all_from_date_counted_by_status_and_day(Time.new(2016, 02, 20)) }
156-
157-
it { expect(result).to be_a(Hash) }
158-
it { expect(result['done'].count).to eq 2 }
159-
it { expect(result.dig('closed', Date.new(2016, 02, 22))).to eq 1 }
160-
end
161-
162143
let(:date) { Date.new(2016, 02, 18) }
163144

164145
it 'returns array of tasks' do
165146
expect(repo.all_from_date(date)).to be_a(Array)
166147
expect(repo.all_from_date(date).count).to eq 8
167148
end
168-
it { expect(repo.all_from_date(date, 'in progress').count).to eq 2 }
169-
it { expect(repo.all_from_date(date, 'done').count).to eq 2 }
170-
it { expect(repo.all_from_date(date, 'closed').count).to eq 2 }
171-
it { expect(repo.all_from_date(date, 'assigned').count).to eq 2 }
149+
150+
it 'returns correct tasks for statuses' do
151+
expect(repo.all_from_date(date, 'in progress').count).to eq 2
152+
expect(repo.all_from_date(date, 'done').count).to eq 2
153+
expect(repo.all_from_date(date, 'closed').count).to eq 2
154+
expect(repo.all_from_date(date, 'assigned').count).to eq 2
155+
end
156+
end
157+
158+
describe '#all_from_date_counted_by_status_and_day' do
159+
before do
160+
(-2..2).each do |days_count|
161+
Timecop.freeze(Time.utc(2016, 02, 20 + days_count)) do
162+
Fabricate.create(:task, status: 'done')
163+
Fabricate.create(:task, status: 'in progress')
164+
Fabricate.create(:task, status: 'closed')
165+
Fabricate.create(:task, status: 'assigned')
166+
end
167+
end
168+
end
169+
170+
it 'returns correct tasks' do
171+
result = repo.all_from_date_counted_by_status_and_day(Time.utc(2016, 02, 20))
172+
expect(result).to be_a(Hash)
173+
expect(result['done'].count).to eq 2
174+
expect(result.dig('closed', Date.new(2016, 02, 22))).to eq 1
175+
end
172176
end
173177

174178
describe '#on_moderation_for_user' do

0 commit comments

Comments
 (0)