Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
# 12 fixed ticket about empty association errors
  • Loading branch information
Jessy Bernal committed Dec 13, 2008
1 parent 46fe6f9 commit e7763ec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/controllers/rows_controller.rb
Expand Up @@ -12,11 +12,14 @@ def index
redirect_to datab_table_path(@datab, @table)
return
end

rows = @table.ar_class.all :conditions => {params[:field] => params[:value]}
@rows = WillPaginate::Collection.create(1, rows.size) do |pager|
pager.replace rows
pager.total_entries = rows.size
if rows.empty?
@rows = []
else
@rows = WillPaginate::Collection.create(1, rows.size) do |pager|
pager.replace rows
pager.total_entries = rows.size
end
end
end

Expand Down
7 changes: 7 additions & 0 deletions app/views/rows/index.html.erb
@@ -1,6 +1,13 @@
<% @title = @table.name + " #{params[:field]} = " + params[:value] %>
<% if @rows.empty? %>
<div class="notification">0 results found in <%= @table.name %> matching <%= params[:field] %> = <%= params[:value] %></div>
<% else %>
<%= number_with_delimiter @rows.size %> records

<%= render :partial => "/tables/browse", :locals => {
:columns => @table.columns,
:rows => @rows
} %>
<% end%>
23 changes: 23 additions & 0 deletions test/functional/rows_controller_test.rb
@@ -1,4 +1,27 @@
require 'test_helper'

class RowsControllerTest < ActionController::TestCase

def setup
super
@request.session[:username] = @@config['user']
@request.session[:password] = @@config['password']
create_database 'rbdb_test1' do |datab|
datab.create_table 'databs' do |t|
t.string :field1, :limit => 1
t.integer :association_id, :null => false
t.boolean :test, :null => false, :default => false
end
datab.create_table 'associations' do |t|
t.string :name
end
end
end

should "display 0 result if no data found in association" do
get :index, :id => 'databs', :datab_id => 'rbdb_test1', :field=>'association_id', :value => '82533'
assert_response :success
end


end

0 comments on commit e7763ec

Please sign in to comment.