Skip to content

Commit

Permalink
removing acts_as_list
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Jul 25, 2011
1 parent 3f5a70f commit fdc900e
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 14 deletions.
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -5,7 +5,6 @@ gem "rails", "3.0.9"
gem "mysql2"
gem "redcarpet"
gem "coderay"
gem "acts_as_list"
gem "thinking-sphinx", ">= 2.0.1", :require => "thinking_sphinx"
gem "whenever", :require => false
gem "will_paginate", ">= 3.0.pre2"
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Expand Up @@ -42,7 +42,6 @@ GEM
activemodel (= 3.0.9)
activesupport (= 3.0.9)
activesupport (3.0.9)
acts_as_list (0.1.2)
addressable (2.2.5)
ancestry (1.2.3)
activerecord (>= 2.2.2)
Expand Down Expand Up @@ -232,7 +231,6 @@ PLATFORMS
ruby

DEPENDENCIES
acts_as_list
ancestry
cancan!
capistrano
Expand Down
1 change: 1 addition & 0 deletions app/controllers/episodes_controller.rb
Expand Up @@ -24,6 +24,7 @@ def show
end

def new
@episode.position = Episode.maximum(:position).to_i + 1
end

def create
Expand Down
1 change: 0 additions & 1 deletion app/models/comment.rb
Expand Up @@ -8,7 +8,6 @@ class Comment < ActiveRecord::Base

has_paper_trail
has_ancestry
acts_as_list :scope => :episode

def request=(request)
self.user_ip = request.remote_ip
Expand Down
9 changes: 8 additions & 1 deletion app/models/episode.rb
Expand Up @@ -4,7 +4,6 @@ class Episode < ActiveRecord::Base
has_many :tags, :through => :taggings

has_paper_trail
acts_as_list

scope :published, lambda { where('published_at <= ?', Time.now.utc) }
scope :unpublished, lambda { where('published_at > ?', Time.now.utc) }
Expand Down Expand Up @@ -149,6 +148,14 @@ def fetch_file_size(path)
end
end

def previous
self.class.where("position < ?", position).order("position desc").first
end

def next
self.class.where("position > ?", position).order("position").first
end

private

def self.primitive_search_conditions(query, join)
Expand Down
1 change: 1 addition & 0 deletions app/views/episodes/_form.html.erb
Expand Up @@ -2,6 +2,7 @@
<p><strong>Please follow the <%= link_to "moderator guidelines", moderators_path %>.</strong></p>
<%= form_for @episode do |f| %>
<%= f.error_messages %>
<%= field f, :position %>
<%= field f, :name %>
<%= field f, :tag_names, :label => "Tags" %>
<%= field f, :description, :type => :text_area, :rows => 6 %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/episodes/show.html.erb
Expand Up @@ -43,8 +43,8 @@
<li class="selected"><%= tab_link "Show Notes", :view => nil %></li>
<li><%= tab_link pluralize(@episode.comments.size, "Comment"), :view => "comments" %></li>
<li><%= tab_link "Similar Episodes", :view => "similar" %></li>
<%= content_tag :li, link_to("Next Episode >", @episode.lower_item), :class => "next" unless @episode.last_published? || @episode.last? %>
<%= content_tag :li, link_to("< Previous Episode", @episode.higher_item), :class => "previous" unless @episode.first? %>
<%= content_tag :li, link_to("Next Episode >", @episode.next), :class => "next" if !@episode.last_published? && @episode.next %>
<%= content_tag :li, link_to("< Previous Episode", @episode.previous), :class => "previous" if @episode.previous %>
</ul>
<div class="nav_section">
<%= %w[comments similar].include?(params[:view]) ? render(params[:view]) : render("show_notes") %>
Expand Down
16 changes: 13 additions & 3 deletions spec/models/episode_spec.rb
Expand Up @@ -17,8 +17,8 @@

it "should sort recent episodes in descending order" do
Episode.delete_all
e1 = Factory(:episode)
e2 = Factory(:episode)
e1 = Factory(:episode, :position => 1)
e2 = Factory(:episode, :position => 2)
Episode.recent.should == [e2, e1]
end

Expand Down Expand Up @@ -116,7 +116,17 @@

it "has a full name which includes position" do
Episode.delete_all
Factory(:episode, :name => "Foo Bar").full_name.should eq('#1 Foo Bar')
Factory(:episode, :position => 123, :name => "Foo Bar").full_name.should eq('#123 Foo Bar')
end

it "knows the next and previous episode based on position" do
Episode.delete_all
e1 = Factory(:episode, :position => 1)
e2 = Factory(:episode, :position => 6)
e1.previous.should be_nil
e1.next.should eq(e2)
e2.next.should be_nil
e2.previous.should eq(e1)
end

describe "primitive search" do
Expand Down
8 changes: 4 additions & 4 deletions spec/requests/episodes_request_spec.rb
Expand Up @@ -53,10 +53,10 @@
end

it "contains show notes, comments, and similar episodes" do
episode = Factory(:episode, :name => "Blast from the Past", :notes => "Show notes!")
episode = Factory(:episode, :name => "Blast from the Past", :notes => "Show notes!", :position => 1)
Factory(:comment, :content => "Hello world", :episode => episode)
Factory(:episode, :name => "Star Wars")
Factory(:episode, :name => "Past and Present")
Factory(:episode, :name => "Star Wars", :position => 2)
Factory(:episode, :name => "Past and Present", :position => 3)
visit episodes_path
click_on "Blast from the Past"
page.should have_content("Blast from the Past")
Expand Down Expand Up @@ -88,7 +88,7 @@
page.should have_content("not authorized")
end

it "creates a new episode" do
it "creates a new episode with default position" do
login Factory(:user, :admin => true)
visit episodes_path
click_on "New Episode"
Expand Down

0 comments on commit fdc900e

Please sign in to comment.