Skip to content

Commit

Permalink
#id now returns an integer
Browse files Browse the repository at this point in the history
Signed-off-by: hajee <hajee@moretIA.com>
  • Loading branch information
hajee authored and hajee committed Sep 4, 2013
1 parent a066553 commit 23a07f0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 25 deletions.
46 changes: 25 additions & 21 deletions CHANGES.md
@@ -1,35 +1,39 @@
#Changes

##V0.2.0
* __BREAKING CHANGE__ Changed class name `PageRecord::PageRecord` to `PageRecord::Base`. Just a rename should be enough.
* Added `add_attributes` class method. This allows you to just add extra attributes instead of specifying them all
* Added `host_class` class method. Now you are able to set any class as a host class instead of beeing glued to xxxxPage`
##V1.0.3
* Added support for getting the Capybara element of a record.
* #id now returns an integer

##V0.2.1
* Fixed a bug. PageRecord stack dumped when the class contained the name `Page`
##V1.0.2
* Added the id of the record to the inspector.
* inspecting uses the Array variant of Capybara and doesn't wait.

##V0.3.0
* Added rails helpers to make it easy in rails to have a form, recognised by PageRecord
* Added other helpers to mke it easy to add `actions` and `attribute` tags
##V1.0.1
* Fixed a bug in action handling that causes page actions aoutside of a record te be noticed. Refactored the action handling.

##V0.4.0
* Added support for Formtasic
* Added spec's for rails helpers
##V1.0.0
Released to production

##V0.5.0
* Added a rails project containing some cucumber features to demonstrate how it works. The example also shows how to use the rails and Formtastic helpers.
* Added support for form validations. Both in formtastic and in reading the errors
* added a `inspect` for both the class and for the instances. This is __very__ helpfull when dubugging.

##V1.0.0
Released to production
##V0.4.0
* Added support for Formtasic
* Added spec's for rails helpers

##V0.3.0
* Added rails helpers to make it easy in rails to have a form, recognised by PageRecord
* Added other helpers to mke it easy to add `actions` and `attribute` tags

##V0.2.1
* Fixed a bug. PageRecord stack dumped when the class contained the name `Page`

##V0.2.0
* __BREAKING CHANGE__ Changed class name `PageRecord::PageRecord` to `PageRecord::Base`. Just a rename should be enough.
* Added `add_attributes` class method. This allows you to just add extra attributes instead of specifying them all
* Added `host_class` class method. Now you are able to set any class as a host class instead of beeing glued to xxxxPage`

##V1.0.1
* Fixed a bug in action handling that causes page actions aoutside of a record te be noticed. Refactored the action handling.

##V1.0.2
* Added the id of the record to the inspector.
* inspecting uses the Array variant of Capybara and doesn't wait.

##V1.0.3
* Added support for getting the Capybara element of a record.ait.
4 changes: 2 additions & 2 deletions lib/page_record/base.rb
Expand Up @@ -13,7 +13,7 @@ class Base
def initialize(id = nil, selector = nil, filter = nil)
@page = self.class.page
@type = self.class.instance_variable_get('@type')
@id = id.to_s
@id = id.to_i if id
find_record(selector, filter)
end

Expand Down Expand Up @@ -289,7 +289,7 @@ def find_record(selector, filter)
begin
context = self.class.context_for_selector(selector)
@record = context.find("[data-#{@type}-id#{id_text}]#{filter}")
@id = @record["data-#{@type}-id"] if @id.blank?
@id = @record["data-#{@type}-id"].to_i if @id.blank?
rescue Capybara::Ambiguous
raise MultipleRecords, "Found multiple #{@type} record with id #{@id} on page"
rescue Capybara::ElementNotFound
Expand Down
10 changes: 10 additions & 0 deletions spec/attributes_spec.rb
Expand Up @@ -4,6 +4,16 @@

include_context "default context"

describe "#id" do

subject { TeamPage.find(1) }
include_context "page with single table with 3 records"

it "returns the id as an integer" do
expect(subject.id).to eq 1
end
end

describe "#... valid attribute getter" do

subject { TeamPage.find(1) }
Expand Down
2 changes: 1 addition & 1 deletion spec/inspector_spec.rb
Expand Up @@ -61,7 +61,7 @@ class TeamPage < PageRecord::Base; end
subject { TeamPage.find(1).inspect }

it 'returns all attributes' do
expect(subject[:attributes]['id']).to eq '1'
expect(subject[:attributes]['id']).to eq 1
expect(subject[:attributes]['ranking']).to eq '1'
expect(subject[:attributes]['name']).to eq 'Ajax'
expect(subject[:attributes]['points']).to eq '10'
Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared_examples.rb
Expand Up @@ -26,7 +26,7 @@
end

it "returns the record identified by the id" do
expect(subject.id).to eq '1'
expect(subject.id).to eq 1
end

end
Expand Down

0 comments on commit 23a07f0

Please sign in to comment.