Skip to content

Commit

Permalink
Changed syntax of raw methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Bert Hajee authored and Bert Hajee committed Jun 13, 2013
1 parent fc22500 commit 742c34b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/page_record/attribute_accessors.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module PageRecord
class PageRecord
def read_attribute_raw(attribute)
def read_attribute?(attribute)
begin
@record.find("[data-attribute-for='#{attribute}']")
rescue Capybara::ElementNotFound
Expand All @@ -9,13 +9,13 @@ def read_attribute_raw(attribute)
end

def read_attribute( attribute)
element = self.send("#{attribute}_raw")
element = self.send("#{attribute}?")
tag = element.tag_name
textelement?(tag) ? element.value : element.text
end

def write_attribute( attribute, value)
element = self.send("#{attribute}_raw")
element = self.send("#{attribute}?")
tag = element.tag_name
raise NotInputField unless textelement?(tag)
element.set(value)
Expand Down
6 changes: 3 additions & 3 deletions lib/page_record/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def self.attributes(new_attributes)
def self.define_accessor_methods(base)
base.instance_eval do
@attributes.each do | attribute |
define_method("#{attribute}_raw") do
read_attribute_raw(attribute)
define_method("#{attribute}?") do
read_attribute?(attribute)
end
define_method(attribute) do
read_attribute(attribute)
Expand All @@ -57,7 +57,7 @@ def self.define_accessor_methods(base)
def self.undefine_accessor_methods(base)
base.instance_eval do
@attributes.each do | attribute |
remove_method("#{attribute}_raw")
remove_method("#{attribute}?")
remove_method(attribute)
remove_method("#{attribute}=")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/page_record/page_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module PageRecord
class PageRecord

attr_reader :id
alias :id_raw :id
alias :id? :id

def initialize(id="", selector="", filter="")
@page = self.class.page
Expand Down
12 changes: 6 additions & 6 deletions spec/page_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ class TeamPage < PageRecord::PageRecord
end
end

it "responds <attribute>_raw of corresponding AR Class" do
it "responds <attribute>? of corresponding AR Class" do
Team.attribute_names.each do |attribute|
expect(subject).to respond_to("#{attribute}_raw")
expect(subject).to respond_to("#{attribute}?")
end
end

Expand Down Expand Up @@ -310,21 +310,21 @@ class TeamPage < PageRecord::PageRecord

end

describe "#..._raw " do
describe "#...? " do

subject {TeamPage.find(1)}

context "attribute is on page" do

it "returns the dom object" do
expect( subject.name_raw.class).to eq Capybara::Node::Simple
expect( subject.name?.class).to eq Capybara::Node::Simple
end
end

context "attribute not on page" do

it "raises error PageRecord::AttributeNotFound" do
expect{subject.goals_raw}.to raise_error(PageRecord::AttributeNotFound)
expect{subject.goals?}.to raise_error(PageRecord::AttributeNotFound)
end

end
Expand Down Expand Up @@ -405,7 +405,7 @@ class TeamPage < PageRecord::PageRecord

end

describe "#...raw action methods" do
describe "#...? action methods" do
pending
end

Expand Down

0 comments on commit 742c34b

Please sign in to comment.