Skip to content

Commit

Permalink
Added table_column_matrix test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfox1985 committed Jul 17, 2015
1 parent 9e09ad4 commit d670c26
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/wice/table_column_matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ def get_column_by_model_class_and_column_name(model_class, column_name) #:nodoc
end

def get_column_in_default_model_class_by_column_name(column_name) #:nodoc:
fail WiceGridException.new('Cannot search for a column in a default model as the default model is not set') if @default_model_class.nil?
if @default_model_class.nil?
fail WiceGridException.new("Cannot search for this column(#{column_name}) in a default model(#{@default_model_class}) as the default model is not set")
end

self[@default_model_class][column_name]
end

Expand All @@ -44,6 +47,7 @@ def init_columns_of_table(model) #:nodoc:
@by_table_names[model.table_name] = self[model]
self[model].each_value { |c| c.model = model }
end

alias_method :<<, :init_columns_of_table
end
end
15 changes: 15 additions & 0 deletions spec/wice/lib/table_column_matrix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ module Wice
it 'should set default_model_class' do
table = TableColumnMatrix.new
table.default_model_class = Dummy

expect(table.class).to eq(TableColumnMatrix)
end

it 'should get column' do
table = TableColumnMatrix.new
table.default_model_class = Dummy

expect(Dummy.columns).to include(table.get_column_by_model_class_and_column_name(Dummy, :name))
expect(Dummy.columns).to include(table.get_column_in_default_model_class_by_column_name(:name))
end

it 'should get column not initialized' do
table = TableColumnMatrix.new
expect {table.get_column_in_default_model_class_by_column_name(:name) }.to raise_error
end
end
end

0 comments on commit d670c26

Please sign in to comment.