Skip to content

Commit

Permalink
Merge pull request ossboard-org#171 from likeath/fix/specs-and-deprec…
Browse files Browse the repository at this point in the history
…ations

Fix deprecations & specs
  • Loading branch information
davydovanton authored Sep 27, 2017
2 parents b8f4fc8 + 88e087d commit 18bceea
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion apps/admin/views/tasks/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Index
include Admin::View

def tasks
TaskRepository.new.tasks.order{ id.desc }.as(Task).to_a
TaskRepository.new.tasks.order{ id.desc }.map_to(Task).to_a
end

def repository_name(task)
Expand Down
2 changes: 1 addition & 1 deletion apps/admin/views/users/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Index
include Admin::View

def users
UserRepository.new.users.order{ id.desc }.as(User).to_a
UserRepository.new.users.order{ id.desc }.map_to(User).to_a
end

def banned_users
Expand Down
2 changes: 1 addition & 1 deletion lib/ossboard/repositories/task_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def assigned_tasks_for_user(user)
private

def all_from_date_request(from, status = nil)
request = tasks.where("created_at > '#{from}'").where("created_at < '#{Time.now}'")
request = tasks.where { (created_at > from) & (created_at < Time.now) }
request = request.where(status: status) if status
request
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ossboard/repositories/user_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ def all_with_points_and_tasks
private

def all_from_date_request(from)
users.where("created_at > '#{from}'").where("created_at < '#{Time.now}'")
users.where { (created_at > from) & (created_at < Time.now) }
end
end
54 changes: 29 additions & 25 deletions spec/ossboard/repositories/task_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@
end

describe '#all_from_date' do
before(:all) do
before do
3.times do |i|
random_days_count = i * 60 * 60 * 24
Timecop.freeze(Time.new(2016, 02, 20) - random_days_count) do
Timecop.freeze(Time.utc(2016, 02, 20) - random_days_count) do
Fabricate.create(:task, status: 'done')
Fabricate.create(:task, status: 'in progress')
Fabricate.create(:task, status: 'closed')
Expand All @@ -140,35 +140,39 @@
Timecop.freeze(Time.now + (2 * 60 * 60 * 24)) { Fabricate.create(:task) }
end

describe '#all_from_date_counted_by_status_and_day' do
before(:all) do
3.times do |i|
Timecop.freeze(Time.utc(2016, 02, 20 + i)) do
Fabricate.create(:task, status: 'done')
Fabricate.create(:task, status: 'in progress')
Fabricate.create(:task, status: 'closed')
Fabricate.create(:task, status: 'assigned')
end
end
end

let (:result) { repo.all_from_date_counted_by_status_and_day(Time.new(2016, 02, 20)) }

it { expect(result).to be_a(Hash) }
it { expect(result['done'].count).to eq 2 }
it { expect(result.dig('closed', Date.new(2016, 02, 22))).to eq 1 }
end

let(:date) { Date.new(2016, 02, 18) }

it 'returns array of tasks' do
expect(repo.all_from_date(date)).to be_a(Array)
expect(repo.all_from_date(date).count).to eq 8
end
it { expect(repo.all_from_date(date, 'in progress').count).to eq 2 }
it { expect(repo.all_from_date(date, 'done').count).to eq 2 }
it { expect(repo.all_from_date(date, 'closed').count).to eq 2 }
it { expect(repo.all_from_date(date, 'assigned').count).to eq 2 }

it 'returns correct tasks for statuses' do
expect(repo.all_from_date(date, 'in progress').count).to eq 2
expect(repo.all_from_date(date, 'done').count).to eq 2
expect(repo.all_from_date(date, 'closed').count).to eq 2
expect(repo.all_from_date(date, 'assigned').count).to eq 2
end
end

describe '#all_from_date_counted_by_status_and_day' do
before do
(-2..2).each do |days_count|
Timecop.freeze(Time.utc(2016, 02, 20 + days_count)) do
Fabricate.create(:task, status: 'done')
Fabricate.create(:task, status: 'in progress')
Fabricate.create(:task, status: 'closed')
Fabricate.create(:task, status: 'assigned')
end
end
end

it 'returns correct tasks' do
result = repo.all_from_date_counted_by_status_and_day(Time.utc(2016, 02, 20))
expect(result).to be_a(Hash)
expect(result['done'].count).to eq 2
expect(result.dig('closed', Date.new(2016, 02, 22))).to eq 1
end
end

describe '#on_moderation_for_user' do
Expand Down

0 comments on commit 18bceea

Please sign in to comment.