spec/utils_spec.rb in tableficate-0.2.1 vs spec/utils_spec.rb in tableficate-0.3.0
- old
+ new
@@ -1,11 +1,51 @@
require 'spec_helper'
describe Tableficate::Utils do
- it 'should construct a path with no theme' do
- Tableficate::Utils::template_path('template.rb').should == 'tableficate/template.rb'
+ describe 'template_path' do
+ before(:each) do
+ @template = mock('Template')
+ @template.stub!(:lookup_context).and_return(ActionView::LookupContext.new([]))
+ end
+
+ it 'should construct a path with no theme' do
+ @template.lookup_context.stub(:exists?).and_return(true)
+
+ Tableficate::Utils::template_path(@template, 'table').should == 'tableficate/table'
+ end
+
+ it 'should construct a path with a theme' do
+ @template.lookup_context.stub(:exists?).and_return(true)
+
+ Tableficate::Utils::template_path(@template, 'table', 'futuristic').should == 'tableficate/futuristic/table'
+ end
+
+ it 'should fallback to a path with no theme if the theme does not have the requested partial' do
+ @template.lookup_context.should_receive(:exists?) do |*args|
+ (args.first == 'tableficate/table')
+ end
+
+ Tableficate::Utils::template_path(@template, 'table', 'futuristic').should == 'tableficate/table'
+ end
end
- it 'should construct a path with a theme' do
- Tableficate::Utils::template_path('template.rb', 'futuristic').should == 'tableficate/futuristic/template.rb'
+ describe 'find_column_type' do
+ it 'should find the column type' do
+ Tableficate::Utils::find_column_type(NobelPrizeWinner, :first_name).should == :string
+ end
+
+ it 'should find the column in a join' do
+ Tableficate::Utils::find_column_type(NobelPrizeWinner.joins(:nobel_prizes), :year).should == :integer
+
+ # pluralization of the join type should be accounted for
+ Tableficate::Utils::find_column_type(NobelPrize.joins(:nobel_prize_winner), :birthdate).should == :date
+ end
+
+ it 'should find the column for manual joins' do
+ Tableficate::Utils::find_column_type(NobelPrizeWinner.joins('JOIN nobel_prizes ON nobel_prizes.nobel_prize_winner_id = nobel_prize_winners.id'), :shared).should == :boolean
+ end
+
+ it 'should return `nil` for unknown columns' do
+ Tableficate::Utils::find_column_type(NobelPrizeWinner, :foo).should == nil
+ end
end
end