jcs/lobsters — pull request #163 by walle (2014-08-04 11:40:07+00:00)
Title: Upvoted functionality. Bringing #49 up to speed.

I've tried to bring pull request #49 up to speed against latest master.

First time working with the lobsters source code so would appreciate if someone took a look at it.

The tests are failing locally for me, but the same fails exists in latest master. I think it is because I used an sqlite database to get the development environment up fast. The errors are sqlite exceptions.

```
Failures:

1) StoryRepository#top filtering 2 weeks should not include #, markeddown_description: nil, story_cache: nil, comments_count: 0, merged_story_id: nil>
Failure/Error: it { should_not include month_ago }
ActiveRecord::StatementInvalid:
SQLite3::SQLException: near "2": syntax error: SELECT "stories".* FROM "stories" WHERE "stories"."merged_story_id" IS NULL AND "stories"."is_expired" = 0 AND (created_at >= (NOW() - INTERVAL 2 WEEK)) ORDER BY (CAST(upvotes AS integer) - CAST(downvotes AS integer)) DESC
# ./spec/models/story_repository_spec.rb:156:in `block (5 levels) in '

2) StoryRepository#top filtering 2 month should include #, markeddown_description: nil, story_cache: nil, comments_count: 0, merged_story_id: nil>
Failure/Error: it { should include month_ago }
ActiveRecord::StatementInvalid:
SQLite3::SQLException: near "2": syntax error: SELECT "stories".* FROM "stories" WHERE "stories"."merged_story_id" IS NULL AND "stories"."is_expired" = 0 AND (created_at >= (NOW() - INTERVAL 2 MONTH)) ORDER BY (CAST(upvotes AS integer) - CAST(downvotes AS integer)) DESC
# ./spec/models/story_repository_spec.rb:162:in `block (5 levels) in '

3) StoryRepository#top filtering 2 month should not include #, markeddown_description: nil, story_cache: nil, comments_count: 0, merged_story_id: nil>
Failure/Error: it { should_not include ten_month_ago }
ActiveRecord::StatementInvalid:
SQLite3::SQLException: near "2": syntax error: SELECT "stories".* FROM "stories" WHERE "stories"."merged_story_id" IS NULL AND "stories"."is_expired" = 0 AND (created_at >= (NOW() - INTERVAL 2 MONTH)) ORDER BY (CAST(upvotes AS integer) - CAST(downvotes AS integer)) DESC
# ./spec/models/story_repository_spec.rb:163:in `block (5 levels) in '

4) StoryRepository#top ordering orders by votes difference
Failure/Error: expect(scope).to eq [s3, s2, s4, s1]
ActiveRecord::StatementInvalid:
SQLite3::SQLException: near "12": syntax error: SELECT "stories".* FROM "stories" WHERE "stories"."merged_story_id" IS NULL AND "stories"."is_expired" = 0 AND (created_at >= (NOW() - INTERVAL 12 MONTH)) ORDER BY (CAST(upvotes AS integer) - CAST(downvotes AS integer)) DESC
# ./spec/models/story_repository_spec.rb:176:in `block (4 levels) in '
```

Hopefully this can be merged this time.