Skip to content

Commit

Permalink
Refactoring routes, added legacy "posts.rss" route, updated tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
vasinov committed Dec 28, 2012
1 parent 7c27647 commit e9ba2ad
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 40 deletions.
14 changes: 7 additions & 7 deletions Gemfile.lock
Expand Up @@ -55,7 +55,7 @@ GEM
rails (~> 3.0)
arel (3.0.2)
bcrypt-ruby (3.0.1)
bootstrap-rails-engine (1.2.1)
bootstrap-rails-engine (1.2.2)
railties (>= 3.0)
builder (3.0.4)
cancan (1.6.8)
Expand Down Expand Up @@ -106,7 +106,7 @@ GEM
mime-types (1.19)
mini_magick (3.4)
subexec (~> 0.2.1)
multi_json (1.3.7)
multi_json (1.5.0)
orm_adapter (0.4.0)
polyglot (0.3.3)
rack (1.4.1)
Expand All @@ -131,22 +131,22 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.0.2)
rake (10.0.3)
rakismet (1.3.0)
rdoc (3.12)
json (~> 1.4)
rspec-core (2.12.0)
rspec-expectations (2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.0)
rspec-mocks (2.12.1)
rspec-rails (2.12.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
sass (3.2.3)
sass (3.2.4)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
Expand Down
11 changes: 3 additions & 8 deletions app/controllers/almanac/blogs_controller.rb
Expand Up @@ -5,7 +5,7 @@ class BlogsController < ApplicationController
load_and_authorize_resource class: Almanac::Blog
respond_to :html

before_filter :only => [:show, :edit, :update, :delete] do |controller|
before_filter :only => [:show, :update, :delete] do |controller|
@blog = Blog.find(params[:id])
end

Expand Down Expand Up @@ -39,6 +39,8 @@ def create
end

def edit
@blog = Blog.first

respond_to do |format|
format.html
end
Expand All @@ -53,12 +55,5 @@ def update
end
end
end

def spam
@comments = Comment.spam

respond_with(@comments) do |format|
end
end
end
end
8 changes: 8 additions & 0 deletions app/controllers/almanac/comments_controller.rb
Expand Up @@ -37,5 +37,13 @@ def destroy
end
end
end

def spam
@blog = Blog.first
@comments = Comment.spam

respond_with(@comments) do |format|
end
end
end
end
4 changes: 2 additions & 2 deletions app/views/almanac/blogs/_topbar.html.haml
@@ -1,5 +1,5 @@
%ul.nav.nav-tabs
%li{ :class => (action_name == "edit") ? "active" : ""}
= link_to "Settings", edit_blog_path(@blog)
= link_to "Settings", edit_blog_path
%li{ :class => (action_name == "spam") ? "active" : ""}
= link_to "Spam", spam_blog_path(@blog)
= link_to "Spam", spam_comments_path
5 changes: 5 additions & 0 deletions app/views/almanac/comments/_topbar.html.haml
@@ -0,0 +1,5 @@
%ul.nav.nav-tabs
%li{ :class => (action_name == "edit") ? "active" : ""}
= link_to "Settings", edit_blog_path
%li{ :class => (action_name == "spam") ? "active" : ""}
= link_to "Spam", spam_comments_path
File renamed without changes.
2 changes: 1 addition & 1 deletion app/views/layouts/almanac/application.html.haml
Expand Up @@ -28,7 +28,7 @@
= link_to(new_post_path) do
%img{ :src => asset_path('almanac/icons/compose.png') }
- unless cannot? :manage, @blog
= link_to(edit_blog_path(@blog)) do
= link_to(edit_blog_path) do
%img{ :src => asset_path('almanac/icons/gear.png') }
= link_to("#{root_path}feed.rss") do
%img{ :src => asset_path('almanac/icons/feed.png') }
Expand Down
16 changes: 10 additions & 6 deletions config/routes.rb
Expand Up @@ -2,16 +2,20 @@
root :to => "posts#index"

match "new_blog" => "blogs#new", :as => "new_blog"
match "edit_blog/:id" => "blogs#edit", :as => "edit_blog"
resources :blogs do
member do
get "spam" => "blogs#spam"
match "edit_blog" => "blogs#edit", :as => "edit_blog"

resources :blogs

resources :comments do
collection do
get "spam" => "comments#spam"
end
end

match "feed" => "posts#index", :format => "rss"
match "posts.rss" => "posts#index", :format => "rss"
match "feed.rss" => "posts#index", :format => "rss"
match ":id/edit" => "posts#edit", :as => "edit_post"
match "new" => "posts#new", :as => "new_post"
match "new_post" => "posts#new", :as => "new_post"
match "drafts/:id" => "posts#draft", :as => "draft", :via => :get
match ":slug" => "posts#show", :as => "post", :via => :get
match "posts" => "posts#create", :as => "posts", :via => :post
Expand Down
16 changes: 0 additions & 16 deletions spec/controllers/blogs_controller_spec.rb
Expand Up @@ -61,20 +61,4 @@
end
end
end

describe "GET spam" do
before :each do
@blog = create(:blog)
post = create(:post_with_comments, comments_count: 10, blog_id: @blog.id)
@spam_comments = create_list(:spam_comment, 5, post_id: post.id)
end
it "returns spam comments" do
get :spam, :use_route => :almanac, id: @blog.id
assigns(:comments).should eq(@spam_comments)
end
it "renders the spam page" do
get :spam, :use_route => :almanac, id: @blog.id
response.should render_template :spam
end
end
end
15 changes: 15 additions & 0 deletions spec/controllers/comments_controller_spec.rb
Expand Up @@ -48,4 +48,19 @@
response.should redirect_to @post
end
end

describe "GET spam" do
before :each do
post = create(:post_with_comments, comments_count: 10, blog_id: @post.blog.id)
@spam_comments = create_list(:spam_comment, 5, post_id: post.id)
end
it "returns spam comments" do
get :spam, :use_route => :almanac, id: @post.blog.id
assigns(:comments).should eq(@spam_comments)
end
it "renders the spam page" do
get :spam, :use_route => :almanac, id: @post.blog.id
response.should render_template :spam
end
end
end

0 comments on commit e9ba2ad

Please sign in to comment.