"Recency" is a weird word...

element
Marcin Kulik 9 years ago
parent f8d28b4b7c
commit 2e3fd29287

@ -1,6 +1,6 @@
class Asciicast < ActiveRecord::Base
ORDER_MODES = { recency: 'created_at', popularity: 'views_count' }
ORDER_MODES = { date: 'created_at', popularity: 'views_count' }
mount_uploader :stdin_data, StdinDataUploader
mount_uploader :stdin_timing, StdinTimingUploader
@ -24,10 +24,10 @@ class Asciicast < ActiveRecord::Base
validates :terminal_lines, presence: true, numericality: { greater_than: 0, less_than_or_equal_to: 500 }
scope :featured, -> { where(featured: true) }
scope :by_recency, -> { order("created_at DESC") }
scope :by_date, -> { order("created_at DESC") }
scope :by_random, -> { order("RANDOM()") }
scope :non_private, -> { where(private: false) }
scope :homepage_latest, -> { non_private.by_recency.limit(6).includes(:user) }
scope :homepage_latest, -> { non_private.by_date.limit(6).includes(:user) }
scope :homepage_featured, -> { non_private.featured.by_random.limit(6).includes(:user) }
before_create :generate_secret_token

@ -1,7 +1,7 @@
class BrowsePagePresenter
DEFAULT_CATEGORY = :public
DEFAULT_ORDER = :recency
DEFAULT_ORDER = :date
PER_PAGE = 12
attr_reader :scope, :category, :order, :page, :per_page

@ -17,7 +17,7 @@
<div class="sorting">
<span>Sort by </span>
<div class="btn-group btn-group-sm">
<%= link_to 'recency', "?order=recency", class: "btn btn-default #{'active' if page.order == :recency}" %>
<%= link_to 'date', "?order=date", class: "btn btn-default #{'active' if page.order == :date}" %>
<%= link_to 'popularity', "?order=popularity", class: "btn btn-default #{'active' if page.order == :popularity}" %>
</div>
</div>

@ -19,7 +19,7 @@ describe AsciicastsController do
describe '#index' do
before do
get :index, category: 'featured', order: 'recency', page: '2'
get :index, category: 'featured', order: 'date', page: '2'
end
it { should be_success }

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
require 'rails_helper'
require 'tempfile'
@ -66,8 +68,8 @@ describe Asciicast do
context "when category is :all" do
let(:category) { :all }
context "and order is :recency" do
let(:order) { :recency }
context "and order is :date" do
let(:order) { :date }
it { should eq([asciicast_2, asciicast_1, asciicast_4, asciicast_3]) }
end
@ -82,8 +84,8 @@ describe Asciicast do
context "when category is :featured" do
let(:category) { :featured }
context "and order is :recency" do
let(:order) { :recency }
context "and order is :date" do
let(:order) { :date }
it { should eq([asciicast_2, asciicast_4]) }
end

Loading…
Cancel
Save