Skip to content

Commit

Permalink
custom_permalink_entry helper returns an Entry, not condition
Browse files Browse the repository at this point in the history
  • Loading branch information
tomykaira committed Feb 19, 2012
1 parent 0a470c6 commit 0221a15
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
8 changes: 3 additions & 5 deletions lib/lokka/app.rb
Expand Up @@ -46,11 +46,9 @@ class App < Sinatra::Base
return redirect(request.path.sub(/\/$/,""))
elsif correct_path = custom_permalink_fix(request.path)
return redirect(correct_path)
elsif cond = custom_permalink_entry_condition(request.path)
if @entry = Entry.first(cond)
status 200
return setup_and_render_entry
end
elsif @entry = custom_permalink_entry(request.path)
status 200
return setup_and_render_entry
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/lokka/helpers.rb
Expand Up @@ -367,7 +367,7 @@ def custom_permalink_fix(path)
nil
end

def custom_permalink_entry_condition(path)
def custom_permalink_entry(path)
r = custom_permalink_parse(path)
conditions, flags = r.inject([{},{}]) {|(conds, flags), (tag, value)|
case tag
Expand Down Expand Up @@ -410,7 +410,7 @@ def custom_permalink_entry_condition(path)
args[time_order.index(last)-1] += 1
conditions[:created_at.lt] = Time.local(*args)
end
conditions
Entry.first(conditions)
rescue => e
nil
end
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/helpers_spec.rb
Expand Up @@ -37,16 +37,16 @@
end
end

describe 'custom_permalink_entry_condition' do
describe 'custom_permalink_entry' do
it 'should parse date condition' do
cond = custom_permalink_entry_condition('/2011/01/09/slug')
cond[:created_at.gte].should == Time.local(2011, 1, 9)
cond[:created_at.lt].should == Time.local(2011, 1, 10)
cond[:slug].should == 'slug'
Entry.should_receive(:first).with(:slug => 'slug',
:created_at.gte => Time.local(2011, 1, 9),
:created_at.lt => Time.local(2011, 1, 10))
custom_permalink_entry('/2011/01/09/slug')
end

it 'should return nil when any error is raised' do
custom_permalink_entry_condition('/no/such/path').should be_nil
custom_permalink_entry('/no/such/path').should be_nil
end
end
end
Expand Down

0 comments on commit 0221a15

Please sign in to comment.