Skip to content

Commit

Permalink
Back to index on the form will go back to page 2, retain field sortin…
Browse files Browse the repository at this point in the history
…g, etc
  • Loading branch information
Francis Hwang authored and Francis Hwang committed Feb 5, 2010
1 parent 3424d30 commit 09752d2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/admin_assistant/request/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def model_class_symbol
end

def origin
@controller.params[:origin] || @controller.request.referer
@controller.params[:origin] || @controller.request.referer ||
{:action => 'index'}
end

def render_single_form(record)
Expand Down
2 changes: 1 addition & 1 deletion lib/views/form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ form_view = AdminAssistant::FormView.new(@record, @admin_assistant, self)
<div class="aa_header">
<h2><%= h(form_view.title) %></h2>
<div class="actions">
<%= link_to('Back to index', :action => 'index') %>
<%= link_to('Back to index', @origin) %>
</div>
</div>
<% if !@record.errors.empty? %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@

describe 'when there are validation errors' do
before :each do
post :create, :blog_post => {:title => ''}
post(
:create, :blog_post => {:title => ''}, :origin => '/admin/blog_posts'
)
end

it 'should not create a new BlogPost' do
Expand All @@ -116,11 +118,12 @@
end

describe '#edit' do
before :all do
before :all do
@blog_post = BlogPost.create! :title => random_word, :user => @user
end

before :each do
@request.env["HTTP_REFERER"] = '/admin/blog_posts'
get :edit, :id => @blog_post.id
end

Expand Down Expand Up @@ -719,6 +722,7 @@
describe '#new' do
before :each do
@alfie = User.find_or_create_by_username 'alfie'
@request.env["HTTP_REFERER"] = '/admin/blog_posts'
get :new
end

Expand Down Expand Up @@ -895,7 +899,11 @@

describe 'when there are validation errors' do
before :each do
post :update, :id => @blog_post.id, :blog_post => {:title => ''}
post(
:update,
:id => @blog_post.id, :blog_post => {:title => ''},
:origin => '/admin/blog_posts'
)
end

it 'should not create a new BlogPost' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@ def test_comes_back_to_index_sorted_by_published_at_after_successful_creation
click_button 'Create'
assert_select 'th.asc', :text => 'Published at'
end

def test_back_to_index_comes_back_to_index_sorted_by_published_at
user = User.find_or_create_by_username 'soren'
BlogPost.create! :title => random_word, :user => user
visit "/admin/blog_posts"
click_link "Published at"
click_link "New blog post"
click_link "Back to index"
assert_select 'th.asc', :text => 'Published at'
end
end

0 comments on commit 09752d2

Please sign in to comment.