Skip to content

Commit

Permalink
Merge branch 'master' into bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric de Villamil committed Jan 15, 2012
2 parents 2bd809b + f7f5515 commit 94a56ce
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/controllers/admin/redirects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Admin::RedirectsController < Admin::BaseController
layout 'administration'

def index
@redirects = Redirect.where("origin is null").order('from_path').page(params[:page]).per(this_blog.admin_display_elements)
@redirects = Redirect.where("origin is null").order('created_at desc').page(params[:page]).per(this_blog.admin_display_elements)
end

def new
Expand Down Expand Up @@ -34,6 +34,9 @@ def new_or_edit

@redirect.attributes = params[:redirect]
if request.post?
if @redirect.from_path.empty? || @redirect.from_path.nil?
@redirect.from_path = @redirect.shorten
end
save_redirect
return
end
Expand Down
1 change: 0 additions & 1 deletion app/models/redirect.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Redirect < ActiveRecord::Base
validates_uniqueness_of :from_path
validates_presence_of :from_path
validates_presence_of :to_path

has_many :redirections
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/redirects/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<h3><label for="redirect_from_path"><%= _("From")%></label> </h3>
<p class='input_text_title'>
<%= this_blog.base_url %>/<%= text_field :redirect, :from_path, :class => 'medium' %>
<span clsas='help'><%= _("Leave empty to shorten a link") %></span>
</p>
</div>
<div>
Expand Down
14 changes: 14 additions & 0 deletions db/migrate/104_adds_created_at_to_redirects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class AddsCreatedAtToRedirects < ActiveRecord::Migration

def self.up
add_column :redirects, :created_at, :datetime
add_column :redirects, :updated_at, :datetime

end

def self.down
remove_column :redirects, :created_at
remove_column :redirects, :updated_at
end
end

10 changes: 9 additions & 1 deletion spec/controllers/admin/redirects_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@
assert_response :redirect, :action => 'index'
end.should change(Redirect, :count)
end


it "test_create with empty from path" do
lambda do
post :edit, 'redirect' => { :from_path => "",
:to_path => "somewhere/else/else" }
assert_response :redirect, :action => 'index'
end.should change(Redirect, :count)
end

describe "#edit" do
before(:each) do
get :edit, :id => Factory(:redirect).id
Expand Down

0 comments on commit 94a56ce

Please sign in to comment.