Skip to content

Commit

Permalink
bundle update and added actions to the inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
Bert Hajee authored and Bert Hajee committed Jul 30, 2013
1 parent c85d284 commit 4014bf0
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/.yardoc/
/pkg/
*.gem

/tmp/
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ GEM
rb-inotify (>= 0.9)
rb-kqueue (>= 0.2)
lumberjack (1.0.4)
method_source (0.8.1)
method_source (0.8.2)
mime-types (1.23)
mini_portile (0.5.1)
minitest (4.7.5)
Expand Down Expand Up @@ -102,7 +102,7 @@ GEM
rspec-core (2.14.4)
rspec-expectations (2.14.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.1)
rspec-mocks (2.14.2)
rspec-rails (2.14.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
Expand Down
24 changes: 23 additions & 1 deletion lib/page_record/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def method_missing(action)
end
end

protected
# @private
def actions
self.class.send('actions_on?',@record)
end

private

# @private
Expand Down Expand Up @@ -90,8 +96,24 @@ def method_missing(action)
end
end

private
protected
# @private
def actions
actions_on?(page)
end

# @private
def actions_on?(context)
actions = context.all("[data-action-for]")
action_hash = Hash.new
actions.each do | action|
name = action['data-action-for']
action_hash[name] = { tag: action.tag_name, text:action.text }
end
action_hash
end

private
# @private
def action_for(action)
element = action_for?(action)
Expand Down
27 changes: 18 additions & 9 deletions lib/page_record/inspector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@ def self.included(base)
end

def inspect
attributes = Hash.new
self.class.attributes.each do | attribute|
begin
attributes[attribute] = self.send(attribute)
rescue AttributeNotFound
attributes[attribute] = '--not found on page--'
end
end
attributes
{
attributes: attributes,
actions: actions
}
end

private
#@private
def attributes
attributes = Hash.new
self.class.attributes.each do | attribute|
begin
attributes[attribute] = self.send(attribute)
rescue AttributeNotFound
attributes[attribute] = '--not found on page--'
end
end
attributes
end

module ClassMethods
def inspect
Expand All @@ -28,6 +36,7 @@ def inspect
selector: self.selector,
filter: self.filter,
attributes: self.attributes,
actions: self.actions
}
end
end
Expand Down
20 changes: 13 additions & 7 deletions spec/inspector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

describe PageRecord::Inspector do

include_context "page with single table with 3 records"

describe '.inspect' do
before do
Expand All @@ -18,8 +19,6 @@ class TeamPage < PageRecord::Base
end


shared_context "page with all elements"

it "returns the type" do
expect(TeamPage.inspect[:type]).to eq 'team'
end
Expand All @@ -40,6 +39,10 @@ class TeamPage < PageRecord::Base
expect(TeamPage.inspect[:attributes]).to eq %w(a b c d e)
end

it "returns all actions" do
expect(TeamPage.inspect[:actions]).to include 'edit', 'next'
end


end

Expand All @@ -54,17 +57,20 @@ class TeamPage < PageRecord::Base; end
Object.send(:remove_const, :TeamPage)
end

include_context "page with single table with 3 records"

subject { TeamPage.find(1).inspect }

it 'returns all attributes' do
expect(subject['ranking']).to eq '1'
expect(subject['name']).to eq 'Ajax'
expect(subject['points']).to eq '10'
expect(subject['goals']).to eq '--not found on page--'
expect(subject[:attributes]['ranking']).to eq '1'
expect(subject[:attributes]['name']).to eq 'Ajax'
expect(subject[:attributes]['points']).to eq '10'
expect(subject[:attributes]['goals']).to eq '--not found on page--'
end

it "returns all actions" do
expect(subject[:actions]).to include 'edit'
end

end
end

4 changes: 4 additions & 0 deletions spec/support/views/page-with-single-table-with-3-records.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
<td data-attribute-for='ranking'>1</td>
<td data-attribute-for='name'>Ajax</td>
<td data-attribute-for='points'>10</td>
<td><a href=# data-action-for='edit'>Edit</a>
</tr>
<tr data-team-id='2' class='champions_league'>
<td data-attribute-for='ranking'>2</td>
<td data-attribute-for='name'>PSV</td>
<td data-attribute-for='points'>8</td>
<td><a href=# data-action-for='edit'>Edit</a>
</tr>
<tr data-team-id='3'>
<td data-attribute-for='ranking'>3</td>
<td data-attribute-for='name'>Feijenoord</td>
<td data-attribute-for='points'>6</td>
<td><a href=# data-action-for='edit'>Edit</a>
</tr>
</table>
<button data-action-for='next'>Next</button>

0 comments on commit 4014bf0

Please sign in to comment.