require 'spec_helper'
class MyFormBuilder
include Datagrid::FormBuilder
end
class MyTemplate
include ActionView::Helpers::FormHelper
end
describe Datagrid::FormBuilder do
let(:template) { ActionView::Base.new}
let(:view) { ActionView::Helpers::FormBuilder.new(:report, _grid, template, {}, Proc.new {|f| })}
subject { view }
describe ".datagrid_filter" do
subject { view.datagrid_filter(_filter)}
context "with default filter type" do
let(:_grid) {
test_report do
scope {Entry}
filter(:name)
end
}
let(:_filter) { :name }
it { should equal_to_dom(
''
)}
end
context "with integer filter type" do
let(:_filter) { :group_id }
let(:_grid) {
test_report do
scope {Entry}
filter(:group_id, :integer)
end
}
it { should equal_to_dom(
''
)}
end
context "with enum filter type" do
let(:_filter) { :category }
let(:_grid) {
test_report do
scope {Entry}
filter(:category, :enum, :select => ["first", "second"])
filter(:category_without_include_blank, :enum, :select => ["first", "second"], :include_blank => false)
filter(:category_with_prompt, :enum, :select => ["first", "second"], :prompt => "My Prompt")
end
}
it { should equal_to_dom(
''
)}
context "when first option is selected" do
before(:each) do
_grid.category = "first"
end
it { should equal_to_dom(
''
)}
end
context "with include_blank option set to false" do
let(:_filter) { :category_without_include_blank }
it { should equal_to_dom(
''
)}
end
context "with prompt option" do
let(:_filter) { :category_with_prompt }
it { should equal_to_dom(
''
)}
end
end
context "with eboolean filter type" do
let(:_filter) { :disabled }
let(:_grid) do
test_report do
scope {Entry}
filter(:disabled, :eboolean)
end
end
it { should equal_to_dom(
''
)}
end
context "with string filter" do
let(:_grid) do
test_report do
scope {Entry}
filter(:name, :string)
end
end
let(:_filter) { :name }
it {should equal_to_dom('')}
end
context "with non multiple filter" do
let(:_grid) do
test_report do
scope {Entry}
filter(
:name, :enum,
:include_blank => false,
:multiple => false,
:select => []
)
end
end
let(:_filter) { :name }
it {should equal_to_dom('')}
end
end
describe ".datagrid_label" do
let(:_grid) do
test_report do
scope {Entry}
filter(:name, :string)
end
end
it "should generate label for filter" do
view.datagrid_label(:name).should equal_to_dom(
''
)
end
it "should pass options through to the helper" do
view.datagrid_label(:name, :class => 'foo').should equal_to_dom(
''
)
end
end
end