Skip to content

Commit

Permalink
Generate menu url from date month/year
Browse files Browse the repository at this point in the history
  • Loading branch information
IngoAlbers committed Jan 12, 2018
1 parent 15ff2bf commit 3b0b7df
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Metrics/MethodLength:
Metrics/AbcSize:
Max: 20

Metrics/ClassLength:
Max: 120

Metrics/BlockLength:
Max: 40
Exclude:
Expand Down
5 changes: 4 additions & 1 deletion app/models/restaurant/lilly_jo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ def ensure_current_year(url)

def menu_url(date)
week = date.strftime('%W')
url = "https://lillyjo.ch/wp-content/uploads/2017/12/lilly-jo_wochenmenue_kw-#{week}.pdf"
month = date.strftime('%m')
year = date.strftime('%Y')

url = "https://lillyjo.ch/wp-content/uploads/#{year}/#{month}/lilly-jo_wochenmenue_kw-#{week}.pdf"

ensure_current_year(url) ? url : fallback_url(url)
end
Expand Down
8 changes: 5 additions & 3 deletions spec/models/restaurant/lilly_jo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
describe '#get_contents' do
it 'returns the correct menus for specified day' do
date = Date.parse('02-08-2017')
stub_request(:get, 'https://lillyjo.ch/wp-content/uploads/2017/12/lilly-jo_wochenmenue_kw-31.pdf')
stub_request(:get, 'https://lillyjo.ch/wp-content/uploads/2017/08/lilly-jo_wochenmenue_kw-31.pdf')
.to_return(status: 200, body: file_fixture('lilly-jo_wochenmenue_kw-31.pdf'))

allow(lilly_jo).to receive(:ensure_current_year).and_return(true)
expect(lilly_jo.get_contents(date)).to eq [menu1, menu2]
end

context 'when the default menu is not of current year' do
it 'returns menus from the fallback url' do
date = Date.parse('03-10-2017')
stub_request(:get, 'https://lillyjo.ch/wp-content/uploads/2017/12/lilly-jo_wochenmenue_kw-40.pdf')
stub_request(:get, 'https://lillyjo.ch/wp-content/uploads/2017/10/lilly-jo_wochenmenue_kw-40.pdf')
.to_return(status: 200, body: file_fixture('lilly-jo_wochenmenue_kw-40.pdf'))
stub_request(:get, 'https://lillyjo.ch/wp-content/uploads/2017/12/lilly-jo_wochenmenue_kw-40-1.pdf')
stub_request(:get, 'https://lillyjo.ch/wp-content/uploads/2017/10/lilly-jo_wochenmenue_kw-40-1.pdf')
.to_return(status: 200, body: file_fixture('lilly-jo_wochenmenue_kw-40-1.pdf'))

expect(lilly_jo.get_contents(date)).to eq [menu3, menu4]
Expand Down

0 comments on commit 3b0b7df

Please sign in to comment.