Skip to content

Commit

Permalink
Remove tight coupling to actions. We'll separate into a submodule later.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbytables committed Dec 15, 2012
1 parent f3b837d commit 8c4303a
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 243 deletions.
6 changes: 0 additions & 6 deletions lib/table_cloth.rb
Expand Up @@ -8,19 +8,13 @@ module TableCloth
autoload :Configuration, 'table_cloth/configuration'
autoload :Builder, 'table_cloth/builder'
autoload :Column, 'table_cloth/column'
autoload :Action, 'table_cloth/action'
autoload :Actions, 'table_cloth/actions'
autoload :Presenter, 'table_cloth/presenter'
autoload :ActionViewExtension, 'table_cloth/action_view_extension'

module Presenters
autoload :Default, 'table_cloth/presenters/default'
end

module Columns
autoload :Action, 'table_cloth/columns/action'
end

def config_for(type)
Configuration.config_for(type).dup
end
Expand Down
21 changes: 0 additions & 21 deletions lib/table_cloth/action.rb

This file was deleted.

23 changes: 0 additions & 23 deletions lib/table_cloth/actions.rb

This file was deleted.

25 changes: 1 addition & 24 deletions lib/table_cloth/base.rb
Expand Up @@ -11,16 +11,6 @@ def initialize(collection, view)
@view = view
end

def columns
@columns ||= self.class.columns.each_with_object({}) do |(column_name, column), columns|
columns[column_name] = column if column.available?(self)
end
end

def has_actions?
self.class.has_actions?
end

class << self
def presenter(klass=nil)
return @presenter = klass if klass
Expand Down Expand Up @@ -55,20 +45,7 @@ def columns

def add_column(name, column)
@columns ||= {}
@columns[name] = column
end

def actions(options={}, &block)
if block_given?
actions = Actions.new(options, &block)
columns[:actions] = actions.column
end

columns[:actions].actions
end

def has_actions?
columns[:actions].present?
@columns[options[:name]] = options
end
end
end
Expand Down
24 changes: 0 additions & 24 deletions lib/table_cloth/columns/action.rb

This file was deleted.

28 changes: 0 additions & 28 deletions spec/lib/actions_spec.rb

This file was deleted.

11 changes: 0 additions & 11 deletions spec/lib/base_spec.rb
Expand Up @@ -59,17 +59,6 @@ def value(object, view)
end
end

context 'actions' do
it "takes a block" do
subject.actions do
action { 'Edit' }
action { 'Delete' }
end

expect(subject.columns[:actions]).to be_kind_of TableCloth::Columns::Action
end
end

context "configuration" do
subject { Class.new(TableCloth::Base) }
let(:sibling1_class) { Class.new(subject) }
Expand Down
73 changes: 0 additions & 73 deletions spec/lib/columns/action_spec.rb

This file was deleted.

38 changes: 12 additions & 26 deletions spec/lib/presenter_spec.rb
Expand Up @@ -10,29 +10,26 @@
let(:view_context) { ActionView::Base.new }
subject { TableCloth::Presenter.new(objects, dummy_table, view_context) }

context ".columns" do
it "returns all columns from the table" do
expect(subject).to have(3).columns
end

it "returns hashes of the column detail" do
subject.columns.each do |column|
expect(column).to be_kind_of Hash
end
end
end

context ".column_names" do
let(:table_instance) { dummy_table.new(objects, view_context) }
before(:each) { table_instance.stub admin?: false, awesome?: true }

it 'returns all names' do
dummy_table.column :name, :email
subject.column_names.should =~ ["Id", "Name", "Email"]
end

it 'includes actions when given' do
dummy_table.actions { action { } }
subject.column_names.should include 'Actions'
end

it 'include actions when only partial are available' do
dummy_table.actions do
action(if: :admin?) { '/' }
action(if: :awesome?) { '/' }
end
subject.column_names.should include 'Actions'
end

it 'uses a name given to it' do
dummy_table.column :email, label: 'Email Address'
subject.column_names.should include 'Email Address'
Expand All @@ -42,18 +39,7 @@
it 'returns all values for a row' do
subject.row_values(dummy_model).should == [dummy_model.id, dummy_model.name, dummy_model.email]
end

it 'returns an edit link in the actions column' do
dummy_table.actions do
action {|object, view| link_to 'Edit', '/model/1/edit' }
end

actions_value = subject.row_values(dummy_model).last
column = Nokogiri::HTML(actions_value)
column.at_xpath('//a')[:href].should == '/model/1/edit'
column.at_xpath('//a').text.should == 'Edit'
end


it 'generates the values for all of the rows' do
expected = objects.map {|o| [o.id, o.name, o.email] }
expect(subject.rows).to eq(expected)
Expand Down
7 changes: 0 additions & 7 deletions spec/support/dummy_table_with_actions.rb

This file was deleted.

0 comments on commit 8c4303a

Please sign in to comment.