Permalink
Browse files

custom_permalink_entry helper returns an Entry, not condition

  • Loading branch information...
1 parent 0a470c6 commit 0221a15dc0fa5864bc9f005ab857b21b3c401a4a @tomykaira tomykaira committed Feb 19, 2012
Showing with 11 additions and 13 deletions.
  1. +3 −5 lib/lokka/app.rb
  2. +2 −2 lib/lokka/helpers.rb
  3. +6 −6 spec/unit/helpers_spec.rb
View
@@ -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
View
@@ -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
@@ -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
View
@@ -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

0 comments on commit 0221a15

Please sign in to comment.