Skip to content

Commit e675133

Browse files
author
Alex
committed
Fixes total_pages method
1 parent e78c034 commit e675133

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

app/models/job.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def self.by_tech(tech_name)
2626
end
2727

2828
def self.total_pages(num_of_items_per_page)
29-
last_two_months.count / num_of_items_per_page
29+
calculation = last_two_months.count / num_of_items_per_page.to_f
30+
calculation.ceil
3031
end
3132
end

spec/controllers/api/v1/recent_jobs_controller_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@
143143
end
144144

145145
it "returns total-pages when api gets called" do
146-
create_list(:job, 50)
146+
create_list(:job, 55)
147147
tech = create(:technology, name: "ruby")
148148
Job.find_each {|job| job.technologies << tech}
149149

150150
get :index, {technology: "ruby"}
151151

152-
expect(response_body["meta"]["total-pages"]).to eq(2)
152+
expect(response_body["meta"]["total-pages"]).to eq(3)
153153
end
154154
end
155155
end

spec/models/job_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@
9696

9797
describe '#total_pages' do
9898
it 'returns the total amount of pages' do
99-
create_list(:job, 4)
99+
create_list(:job, 30)
100100
tech = create(:technology, name: "ruby")
101101
Job.find_each {|job| job.technologies << tech}
102102

103-
expect(Job.count).to eq(4)
104-
expect(Job.total_pages(2)).to eq(2)
103+
expect(Job.count).to eq(30)
104+
expect(Job.total_pages(4)).to eq(8)
105105
end
106106
end
107107
end

0 commit comments

Comments
 (0)