Skip to content

Commit

Permalink
Merge pull request #29 from exAspArk/actions_in_base_class
Browse files Browse the repository at this point in the history
Add method "actions" to Base class by default
  • Loading branch information
bobbytables committed Feb 12, 2014
2 parents b387956 + e9428ce commit 7b05481
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 35 deletions.
3 changes: 0 additions & 3 deletions lib/generators/templates/table.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
class <%= class_name %>Table < TableCloth::Base
# To include actions on this table, uncomment this line
# include TableCloth::Extensions::Actions

# Define columns with the #column method
# column :name, :email

Expand Down
4 changes: 3 additions & 1 deletion lib/table_cloth/base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module TableCloth
class Base
include TableCloth::Extensions::Actions

NoPresenterError = Class.new(Exception)

attr_reader :collection, :view
Expand Down Expand Up @@ -59,4 +61,4 @@ def config
end
end
end
end
end
8 changes: 7 additions & 1 deletion spec/lib/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,10 @@
expect { sibling1_class.config.table.cellpadding = '0' }.not_to change { sibling2_class.config.table.cellpadding }
end
end
end

describe '.actions' do
it 'exists in class' do
expect(subject).to respond_to(:actions)
end
end
end
52 changes: 22 additions & 30 deletions spec/lib/extensions/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,32 @@
describe TableCloth::Extensions::Actions do
let(:dummy_table) { FactoryGirl.build(:dummy_table) }

context "inclusion" do
it "gives the table class an actions method" do
expect { dummy_table.send(:include, described_class) }.to change { dummy_table.respond_to? :actions }.to true
describe '.actions' do
it "yields an ActionCollection block" do
block_type = nil
dummy_table.actions { block_type = self }
expect(block_type).to be_kind_of TableCloth::Extensions::Actions::ActionCollection
end

context ".actions" do
before(:each) { dummy_table.send(:include, described_class) }

it "yields an ActionCollection block" do
block_type = nil
dummy_table.actions { block_type = self }
expect(block_type).to be_kind_of TableCloth::Extensions::Actions::ActionCollection
end

it "creates an actions column on the table" do
dummy_table.actions { }
expect(dummy_table.columns).to have_key :actions
end
it "creates an actions column on the table" do
dummy_table.actions { }
expect(dummy_table.columns).to have_key :actions
end

it "accepts options" do
dummy_table.actions(if: :admin?) { }
expect(dummy_table.columns[:actions][:options]).to have_key :if
end
it "accepts options" do
dummy_table.actions(if: :admin?) { }
expect(dummy_table.columns[:actions][:options]).to have_key :if
end

it "sets a collection key for the column pointing to the collection object" do
dummy_table.actions { }
expect(dummy_table.columns[:actions][:options][:collection]).to be_kind_of TableCloth::Extensions::Actions::ActionCollection
end
it "sets a collection key for the column pointing to the collection object" do
dummy_table.actions { }
expect(dummy_table.columns[:actions][:options][:collection]).to be_kind_of TableCloth::Extensions::Actions::ActionCollection
end

it "sets the column class to an action column" do
dummy_table.actions { }
column = dummy_table.columns[:actions]
expect(column[:class]).to eq(TableCloth::Extensions::Actions::Column)
end
it "sets the column class to an action column" do
dummy_table.actions { }
column = dummy_table.columns[:actions]
expect(column[:class]).to eq(TableCloth::Extensions::Actions::Column)
end
end
end
end

0 comments on commit 7b05481

Please sign in to comment.