page_record 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -3,7 +3,7 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  # - jruby-19mode
6
- - rbx-19mode
6
+ # - rbx-19mode
7
7
  script: bundle exec rspec spec
8
8
  # matrix:
9
9
  # allow_failures:
data/CHANGES.md ADDED
@@ -0,0 +1,6 @@
1
+ #Changes
2
+
3
+ ##V0.2.0
4
+ * __BREAKING CHANGE__ Changed class name `PageRecord::PageRecord` to `PageRecord::Base`. Just a rename should be enough.
5
+ * Added `add_attributes` class method. This allows you to just add extra attributes instead of specifying them all
6
+ * Added `host_class` class method. Now you are able to set any class as a host class instead of beeing glued to xxxxPage`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- page_record (0.0.1)
4
+ page_record (0.2.0)
5
5
  activesupport
6
6
  capybara (~> 2.1.0)
7
7
 
@@ -36,7 +36,7 @@ GEM
36
36
  rack
37
37
  rack-test (0.6.2)
38
38
  rack (>= 1.0)
39
- rake (10.0.4)
39
+ rake (10.1.0)
40
40
  rest-client (1.6.7)
41
41
  mime-types (>= 1.16)
42
42
  rspec (2.13.0)
@@ -51,10 +51,10 @@ GEM
51
51
  multi_json (~> 1.0)
52
52
  simplecov-html (~> 0.7.1)
53
53
  simplecov-html (0.7.1)
54
- sinatra (1.3.6)
54
+ sinatra (1.4.3)
55
55
  rack (~> 1.4)
56
- rack-protection (~> 1.3)
57
- tilt (~> 1.3, >= 1.3.3)
56
+ rack-protection (~> 1.4)
57
+ tilt (~> 1.3, >= 1.3.4)
58
58
  thor (0.18.1)
59
59
  tilt (1.4.1)
60
60
  xpath (2.0.0)
data/README.md CHANGED
@@ -10,10 +10,10 @@ There are a lot of ways you can do this. PageRecord is one of these ways. PageRe
10
10
  TODO explain how it helps in testing
11
11
 
12
12
  ##Documentation
13
- Look at {http://rubydoc.info/github/appdrones/page_record the yard documentation} for details.
13
+ Look at [the yard documentation](http://rubydoc.info/github/appdrones/page_record/PageRecord) for details. Check [Changes](https://github.com/appdrones/page_record/blob/master/CHANGES.md) for (breaking) changes per version.
14
14
 
15
15
  ##Markup
16
- For {PageRecord} to recognise the data on the page, the page __must__ follow certain `html` formatting guidelines.
16
+ For [PageRecord](http://rubydoc.info/github/appdrones/page_record/PageRecord) to recognise the data on the page, the page __must__ follow certain `html` formatting guidelines.
17
17
 
18
18
  __Every__ record on the page __must__ have a `data-type-id='x'` attribute.
19
19
 
@@ -22,7 +22,7 @@ __Every__ record on the page __must__ have a `data-type-id='x'` attribute.
22
22
  ...
23
23
  <tag>
24
24
  ```
25
- Where `1` is the `id` of the record and `type` is the type of record. See {PageRecord::PageRecord.type} for infrmation regarding the `type`.
25
+ Where `1` is the `id` of the record and `type` is the type of record. See [PageRecord::Base.type](http://rubydoc.info/github/appdrones/page_record/PageRecord/Base#type-class_method) for information regarding the `type`.
26
26
 
27
27
  __Every__ attribute of a record, __must__ have a `data-attribute-for='name'` attribute. This tag __must__ be contained inside a tag contaning the `data-type-id='x'`
28
28
 
@@ -38,7 +38,7 @@ Where `attr` is the name of the attribute.
38
38
  ##attributes
39
39
 
40
40
  ###reading the attributes
41
- With {PageRecord}, you can easily access the attributes of a record on the page. After you've got a valid instance of {PageRecord::PageRecord}, you can access all attributes in a normal ruby-like way.
41
+ With [PageRecord](http://rubydoc.info/github/appdrones/page_record/PageRecord), you can easily access the attributes of a record on the page. After you've got a valid instance of [PageRecord::Base](http://rubydoc.info/github/appdrones/page_record/PageRecord/Base), you can access all attributes in a normal ruby-like way.
42
42
 
43
43
  ```ruby
44
44
  champion = TeamPage.find(1)
@@ -53,19 +53,19 @@ Not only can you access the attributes for reading, you can also set the attribu
53
53
  ```
54
54
 
55
55
  ###specifying the attributes
56
- When you define you page class as a subclass of {PageRecord::PageRecord}, it automagicaly looks for a host class. To get the name of your host class, PageRecord removes the `Page` part of you class name and tries to use that class as a host class.
56
+ When you define you page class as a subclass of [PageRecord::Base](http://rubydoc.info/github/appdrones/page_record/PageRecord/Base), it automagicaly looks for a host class. To get the name of your host class, PageRecord removes the `Page` part of you class name and tries to use that class as a host class.
57
57
 
58
58
  Example:
59
59
 
60
60
  ```ruby
61
- class TeamPage < PageRecord::PageRecord
61
+ class TeamPage < PageRecord::Base
62
62
  end
63
63
  ```
64
64
 
65
65
  will result in a host class of `Team`
66
66
 
67
67
  ####what is the host class
68
- The host class is a class who's attributes are mirrored by PageRecord. At this point in time PageRecord only has support for `ActiveRecord` host classes. To be more specific: To be used as a host class, the class must support the method `attribute_names` to return an {::Array} of {::String} of {::Symbol}.
68
+ The host class is a class who's attributes are mirrored by PageRecord. At this point in time PageRecord only has support for `ActiveRecord` host classes. To be more specific: To be used as a host class, the class must support the method `attribute_names` to return an [Array](http://ruby-doc.org/core-2.0/Array.html) of [String](http://ruby-doc.org/core-2.0/String.html) of [Symbol](http://ruby-doc.org/core-2.0/Symbol.html).
69
69
 
70
70
  Example:
71
71
 
@@ -78,12 +78,44 @@ class Team < ActiveRecord::Base
78
78
  #
79
79
  end
80
80
 
81
- class TeamPage < PageRecord::PageRecord
81
+ class TeamPage < PageRecord::Base
82
82
  end
83
83
  ```
84
84
 
85
85
  Then a record from the TeamPage responds to the attributes: `name`, `position`, `points`
86
86
 
87
+ ####what is the host class
88
+ If you want to use a totaly different class name, you can use the `host_class` macro to specify what should be the host class.
89
+
90
+ Example:
91
+
92
+ ```ruby
93
+ class JustSomeClass
94
+ host_class Team
95
+ end
96
+ ```
97
+
98
+ This creates class `JustSomeClass` with the same capabilities as the `TeamPage` class in the previous example.
99
+
100
+ ###Adding some attributes
101
+ If you have a full_name on a page that isn't available in the host_class, you can add that attribute.
102
+
103
+ ```ruby
104
+ class TeamPage < PageRecord::Base
105
+ add_attributes ['full_name']
106
+ end
107
+ ```
108
+
109
+ ###Setting all attributes
110
+ Sometimes it is easier to not have a host class, but just set the attributes your self. You can do this withe the attributes macro.
111
+
112
+ ```ruby
113
+ class JustSomePage < PageRecord::Base
114
+ attributes ['first_name', 'last_name', 'full_name']
115
+ end
116
+ ```
117
+
118
+
87
119
  ##actions
88
120
  PageRecord support record actions and page actions.
89
121
 
@@ -111,7 +143,7 @@ team.save
111
143
 
112
144
  When you call an action method, PageRecord automagicaly clicks the specified HTML element.
113
145
 
114
- Sometimes you don't want to click the element. PageRecord supports this by calling the action routine with a `?`. This returns the {http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Result Capybara Result}. You can do with this element whatever you can do with this element what you want.
146
+ Sometimes you don't want to click the element. PageRecord supports this by calling the action routine with a `?`. This returns the [Capybara Result](http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Result). You can do with this element whatever you can do with this element what you want.
115
147
 
116
148
  ```ruby
117
149
  TeamPage.save?
@@ -144,7 +176,7 @@ TeamPage.save?
144
176
  ```
145
177
 
146
178
  ##Using PageRecord together with Rspec
147
- To use {PageRecord} with Rspec, you need to require it in your `spec_helper.rb` file. To make it work, it needs to be required __after__ capybara.
179
+ To use [PageRecord](http://rubydoc.info/github/appdrones/page_record/PageRecord) with Rspec, you need to require it in your `spec_helper.rb` file. To make it work, it needs to be required __after__ capybara.
148
180
 
149
181
  ```ruby
150
182
  require 'capybara'
@@ -154,7 +186,7 @@ require 'page_record/rspec'
154
186
  Also, you need te make sure your page definitions are included. A good place to store them would be in your support directory.
155
187
 
156
188
  ##Using PageRecord together with Cucumber
157
- To use {PageRecord} with Cucumber, you need to require it in your `env.rb` file. To make it work, it needs to be required __after__ capybara.
189
+ To use [PageRecord](http://rubydoc.info/github/appdrones/page_record/PageRecord) with Cucumber, you need to require it in your `env.rb` file. To make it work, it needs to be required __after__ capybara.
158
190
 
159
191
  ```ruby
160
192
  require 'capybara'
@@ -163,7 +195,7 @@ require 'page_record/cucumber'
163
195
  Also, you need te make sure your page definitions are included. A good place to store them would be in your support directory.
164
196
 
165
197
  ##Using PageRecord standalone
166
- If you are using {PageRecord} outside of Rspec or Cucumber, you also need to require the right files.
198
+ If you are using [PageRecord](http://rubydoc.info/github/appdrones/page_record/PageRecord) outside of Rspec or Cucumber, you also need to require the right files.
167
199
 
168
200
  ```ruby
169
201
  require 'capybara'
@@ -173,7 +205,7 @@ require 'page_record/rspec'
173
205
  You also need te make sure, you set the page variable before you start.
174
206
 
175
207
  ```ruby
176
- PageRecord::PageRecord.page = session
208
+ PageRecord::Base.page = session
177
209
  ```
178
210
 
179
211
  Also, you need te make sure your page definitions are included.
@@ -1,5 +1,5 @@
1
1
  module PageRecord
2
- class PageRecord
2
+ class Base
3
3
  ##
4
4
  # Searches the record for the specified attribute and returns the {http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Result Capybara Result}.
5
5
  # This method is called when you access an attribute with a `?` of a record
@@ -1,7 +1,7 @@
1
1
 
2
2
  module PageRecord
3
3
 
4
- class PageRecord
4
+ class Base
5
5
 
6
6
  attr_reader :id
7
7
  alias :id? :id
@@ -1,5 +1,5 @@
1
1
  module PageRecord
2
- class PageRecord
2
+ class Base
3
3
  ##
4
4
  #
5
5
  # This is the implementation of the page action routine. It has two variants.
@@ -1,5 +1,5 @@
1
1
  module PageRecord
2
- class PageRecord
2
+ class Base
3
3
 
4
4
  # @private
5
5
  def self.inherited(base)
@@ -13,24 +13,35 @@ module PageRecord
13
13
 
14
14
 
15
15
  ##
16
- # Set's the page {PageRecord::PageRecord} uses for all page operations
16
+ # Set's the page {PageRecord::Base} uses for all page operations.
17
+ # when no parameter is given or the parameter is nil, just return the current value
17
18
  #
18
19
  # @param new_page [Cabybara::Session] The Capybara page
19
20
  #
20
21
  # @return [Capybara::Session]
21
22
  #
22
- def self.page=(new_page)
23
- @@page = new_page
23
+ def self.page (new_page = nil)
24
+ new_page ? @@page = new_page : @@page
24
25
  end
25
26
 
26
27
  ##
27
- # Returns the page page {PageRecord::PageRecord} uses for all page operations
28
+ # Set's the page host class
28
29
  #
29
- # @return [Capybara::Session]
30
+ # @param new_host_class an ActiveRecord like class
30
31
  #
31
- def self.page
32
- @@page
33
- end
32
+ # @return [Class]
33
+ #
34
+ def self.host_class (new_host_class = nil)
35
+ if new_host_class
36
+ @host_class = new_host_class
37
+ @host_name = new_host_class.to_s
38
+ @type = @host_name.underscore
39
+ get_attribute_names
40
+ define_class_methods(self)
41
+ define_instance_methods(self)
42
+ end
43
+ @host_class
44
+ end
34
45
 
35
46
  ##
36
47
  # Set's the default selector for this class
@@ -38,7 +49,7 @@ module PageRecord
38
49
  # Example:
39
50
  #
40
51
  # ```ruby
41
- # class TeamPage < PageRecord::PageRecord
52
+ # class TeamPage < PageRecord::Base
42
53
  # selector "#first-table"
43
54
  # end
44
55
  #```
@@ -55,7 +66,7 @@ module PageRecord
55
66
  # Example:
56
67
  #
57
68
  # ```ruby
58
- # class TeamPage < PageRecord::PageRecord
69
+ # class TeamPage < PageRecord::Base
59
70
  # filter ".champions-league"
60
71
  # end
61
72
  #```
@@ -69,43 +80,75 @@ module PageRecord
69
80
  ##
70
81
  # Set's the default type for this class
71
82
  #
72
- # @param new_type [Symbol] The default type to be used for all finders
83
+ # @param new_type [Symbol] The default type to be used for all finders. If type is nil just return the current type
84
+ #
85
+ # @return [Symbol] the type set.
73
86
  #
74
87
  # Example:
75
88
  #
76
89
  # ```ruby
77
- # class TopDivisonPage < PageRecord::PageRecord
90
+ # class TopDivisonPage < PageRecord::Base
78
91
  # type :team
79
92
  # end
93
+ #
94
+ # TopDivisonPage.type # returns :team
80
95
  #```
81
96
  #
82
97
  #
83
- def self.type( new_type)
84
- @type = new_type
98
+ def self.type( new_type = nil)
99
+ new_type ? @type = new_type : @type
85
100
  end
86
101
 
87
102
 
88
103
  ##
89
104
  # Set's the attributes this page recognises. This will override any types
90
- # inherited from the host class
105
+ # inherited from the host class. When you don't specify a parameter, or a nil parameter
106
+ # .attributes will return the current set of attributes
91
107
  #
92
108
  # @param new_attributes [Array] The attributes the page regognises
93
109
  #
110
+ # @return attributes [Array] returns the array of attributes the page recognises
94
111
  # Example:
95
112
  #
96
113
  # ```ruby
97
- # class TopDivisonPage < PageRecord::PageRecord
114
+ # class TopDivisonPage < PageRecord::Base
98
115
  # attributes [:name, :position, :ranking]
99
116
  # end
100
117
  #```
101
118
  #
102
119
  #
103
- def self.attributes(new_attributes)
104
- undefine_class_methods(self)
105
- undefine_instance_methods(self)
106
- @attributes = new_attributes
120
+ def self.attributes(new_attributes = nil)
121
+ if new_attributes
122
+ undefine_class_methods(self)
123
+ undefine_instance_methods(self)
124
+ @attributes = new_attributes
125
+ define_class_methods(self)
126
+ define_instance_methods(self)
127
+ end
128
+ @attributes
129
+ end
130
+
131
+
132
+ ##
133
+ # Add some new attributes to the already availabe attributes
134
+ #
135
+ # @param extra_attributes [Array] The additional attributes the page regognises
136
+ #
137
+ # Example:
138
+ #
139
+ # ```ruby
140
+ # class TopDivisonPage < PageRecord::Base
141
+ # add_attributes [:full_name, :address_line]
142
+ # end
143
+ #```
144
+ #
145
+ #
146
+ def self.add_attributes(extra_attributes)
147
+ @attributes.concat(extra_attributes)
148
+ # TODO check if we can optimise this to only add the new methods
107
149
  define_class_methods(self)
108
150
  define_instance_methods(self)
151
+ @attributes
109
152
  end
110
153
 
111
154
 
@@ -113,14 +156,14 @@ private
113
156
 
114
157
  # @private
115
158
  def self.set_type_name(base)
116
- @base_name = base.to_s.gsub('Page', '')
117
- @type = @base_name.underscore
159
+ @host_name = base.to_s.gsub('Page', '')
160
+ @type = @host_name.underscore
161
+ @host_class = @host_name.constantize
118
162
  end
119
163
 
120
164
  # @private
121
165
  def self.get_attribute_names
122
166
  begin
123
- @host_class = @base_name.constantize
124
167
  @attributes = @host_class.attribute_names.clone
125
168
  @attributes.delete('id') # id is a special case attribute
126
169
  rescue NameError
@@ -1,5 +1,5 @@
1
1
  require 'page_record'
2
2
 
3
3
  Before do
4
- PageRecord::PageRecord.page = page
4
+ PageRecord::Base.page page
5
5
  end
@@ -39,7 +39,7 @@ module PageRecord
39
39
 
40
40
  ##
41
41
  # This {::Exception} is raised when you have not set the page variable
42
- # of the class. Check {PageRecord::PageRecord.page} for details
42
+ # of the class. Check {PageRecord::Base.page} for details
43
43
  #
44
44
  class PageNotSet < Exception
45
45
  end
@@ -14,10 +14,10 @@ module PageRecord
14
14
  # tag. We use these tags to identify the records on the page.
15
15
  #
16
16
  #
17
- class PageRecord
17
+ class Base
18
18
  ##
19
19
  #
20
- # Searches the page and returns an {::Array} of {PageRecord::PageRecord} of instances of
20
+ # Searches the page and returns an {::Array} of {PageRecord::Base} of instances of
21
21
  # that match the selector and the filter. See {file:README.md#markup markup} for more
22
22
  # details about formatting the page.
23
23
  #
@@ -32,7 +32,7 @@ module PageRecord
32
32
  # @param selector [String] selector to use for searching the table on the page
33
33
  # @param filter [String] filter to use on the records on the page
34
34
  #
35
- # @return [Array Pagerecord] The Array containing instances of [PageRecord::PageRecord]
35
+ # @return [Array Pagerecord] The Array containing instances of [PageRecord::Base]
36
36
  # with records that fit the selector and the filter
37
37
  #
38
38
  # @raise [MultipleRecords] if the page contains more then on set of records
@@ -52,7 +52,7 @@ module PageRecord
52
52
 
53
53
  ##
54
54
  #
55
- # Searches the page and returns an instance of {PageRecord::PageRecord} of instances of
55
+ # Searches the page and returns an instance of {PageRecord::Base} of instances of
56
56
  # that matches the given id, selector and the filter. See {file:README.md#markup markup} for more
57
57
  # details about formatting the page.
58
58
  #
@@ -76,7 +76,7 @@ module PageRecord
76
76
  # @param selector [String] selector to use for searching the table on the page
77
77
  # @param filter [String] filter to use on the records on the page
78
78
  #
79
- # @return [Pagerecord] An instance of [PageRecord::PageRecord]
79
+ # @return [Pagerecord] An instance of [PageRecord::Base]
80
80
  #
81
81
  # @raise [MultipleRecords] if the page contains more then on set of records
82
82
  # @raise [RecordNotFound] if the page does not contain any of the specified records
@@ -89,13 +89,13 @@ module PageRecord
89
89
 
90
90
  ##
91
91
  #
92
- # Searches the page and returns an instance of {PageRecord::PageRecord} of instances of
92
+ # Searches the page and returns an instance of {PageRecord::Base} of instances of
93
93
  # that matches the given attribute. See {file:README.md#markup markup} for more
94
94
  # details about formatting the page.
95
95
  #
96
- # Although you can call this yourself, {PageRecord::PageRecord} uses this method for defining a
97
- # finder for all attributes when you define your page class, {PageRecord::PageRecord}
98
- # See {PageRecord::PageRecord.attributes} for more details.
96
+ # Although you can call this yourself, {PageRecord::Base} uses this method for defining a
97
+ # finder for all attributes when you define your page class, {PageRecord::Base}
98
+ # See {PageRecord::Base.attributes} for more details.
99
99
  #
100
100
  # example:
101
101
  #
@@ -110,7 +110,7 @@ module PageRecord
110
110
  # @param selector [String] selector to use for searching the table on the page
111
111
  # @param filter [String] filter to use on the records on the page
112
112
  #
113
- # @return [Pagerecord] An instance of [PageRecord::PageRecord].
113
+ # @return [Pagerecord] An instance of [PageRecord::Base].
114
114
  #
115
115
  # @raise [MultipleRecords] if the page contains more then on set of records
116
116
  # @raise [RecordNotFound] if the page does not contain any of the specified records
@@ -1,5 +1,5 @@
1
1
  module PageRecord
2
- class PageRecord
2
+ class Base
3
3
 
4
4
  ##
5
5
  # This is the implementation of the record action routine. It has two variants.
@@ -2,6 +2,6 @@ require 'page_record'
2
2
 
3
3
  RSpec.configure do |config|
4
4
  config.before(:each) do
5
- PageRecord::PageRecord.page = session
5
+ PageRecord::Base.page session
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module PageRecord
2
- VERSION = "0.0.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/page_record.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'active_support/core_ext'
2
2
  require "page_record/version"
3
- require "page_record/page_record"
3
+ require "page_record/base"
4
4
  require "page_record/finders"
5
5
  require "page_record/instance_actions"
6
6
  require "page_record/attribute_accessors"
@@ -1,12 +1,12 @@
1
1
  require_relative './spec_helper'
2
2
 
3
- describe PageRecord::PageRecord do
3
+ describe PageRecord::Base do
4
4
 
5
5
  include_context "page with single table with 3 records" # Default context
6
6
 
7
7
  before do
8
- class TeamPage < PageRecord::PageRecord; end
9
- PageRecord::PageRecord.page = page
8
+ class TeamPage < PageRecord::Base; end
9
+ PageRecord::Base.page page
10
10
  end
11
11
 
12
12
  describe ".type" do
@@ -17,21 +17,88 @@ describe PageRecord::PageRecord do
17
17
  [ 'id' , 'name', 'points', 'ranking', 'goals']
18
18
  end
19
19
  end
20
- class CamelCasePage < PageRecord::PageRecord; end
20
+ class CamelCasePage < PageRecord::Base; end
21
21
  end
22
22
 
23
- it "returns the internal type of the class" do
24
- pending
25
- expect( CamelCasePage.type).to eq "camel_case"
23
+ context "no type given" do
24
+
25
+ it "returns the internal type of the class " do
26
+ expect( CamelCasePage.type).to eq "camel_case"
27
+ end
26
28
  end
27
29
 
30
+ context "a type given" do
31
+
32
+ before do
33
+ class CamelCasePage < PageRecord::Base
34
+ type :team
35
+ end
36
+ end
37
+
38
+ it "sets the internal type of the class" do
39
+ expect( CamelCasePage.type).to eq :team
40
+ end
41
+ end
42
+
43
+
28
44
  end
29
45
 
30
46
 
31
47
  describe ".attributes" do
48
+
49
+ after do
50
+ Object.send(:remove_const, :TeamPage)
51
+ end
52
+
53
+ context "no parameter given" do
54
+
55
+ it "returns all current recognised attributes" do
56
+ expect(TeamPage.attributes).to eq ['name', 'points', 'ranking', 'goals']
57
+ end
58
+ end
59
+
60
+ context "parameter given" do
61
+
62
+ subject { TeamPage}
63
+
64
+ before do
65
+ class TeamPage < PageRecord::Base
66
+ attributes ['country', 'stadium']
67
+ end
68
+ end
69
+
70
+ it "clears all old class methods" do
71
+ expect(subject).not_to respond_to(:find_by_name)
72
+ expect(subject).not_to respond_to(:find_by_ranking)
73
+ end
74
+
75
+ it "adds new class methods to class " do
76
+ expect(subject).to respond_to(:find_by_country)
77
+ expect(subject).to respond_to(:find_by_stadium)
78
+ end
79
+
80
+ it "clears all old instance methods" do
81
+ expect(subject.new(1)).not_to respond_to(:name)
82
+ expect(subject.new(1)).not_to respond_to(:ranking)
83
+ end
84
+
85
+ it "adds new class methods to class " do
86
+ expect(subject.new(1)).to respond_to(:country)
87
+ expect(subject.new(1)).to respond_to(:stadium)
88
+ end
89
+
90
+ it "returns all current recognised attributes" do
91
+ expect(TeamPage.attributes).to eq ['country', 'stadium']
92
+ end
93
+ end
94
+
95
+ end
96
+
97
+
98
+ describe ".add_attributes" do
32
99
  before do
33
- class TeamPage < PageRecord::PageRecord
34
- attributes ['country', 'stadium']
100
+ class TeamPage < PageRecord::Base
101
+ add_attributes ['country', 'stadium']
35
102
  end
36
103
  end
37
104
 
@@ -41,9 +108,10 @@ describe PageRecord::PageRecord do
41
108
 
42
109
  subject { TeamPage}
43
110
 
44
- it "clears all old class methods" do
45
- expect(subject).not_to respond_to(:find_by_name)
46
- expect(subject).not_to respond_to(:find_by_ranking)
111
+
112
+ it "keeps all old class methods" do
113
+ expect(subject).to respond_to(:find_by_name)
114
+ expect(subject).to respond_to(:find_by_ranking)
47
115
  end
48
116
 
49
117
  it "adds new class methods to class " do
@@ -51,9 +119,9 @@ describe PageRecord::PageRecord do
51
119
  expect(subject).to respond_to(:find_by_stadium)
52
120
  end
53
121
 
54
- it "clears all old instance methods" do
55
- expect(subject.new(1)).not_to respond_to(:name)
56
- expect(subject.new(1)).not_to respond_to(:ranking)
122
+ it "keeps all old instance methods" do
123
+ expect(subject.new(1)).to respond_to(:name)
124
+ expect(subject.new(1)).to respond_to(:ranking)
57
125
  end
58
126
 
59
127
  it "adds new class methods to class " do
@@ -61,38 +129,78 @@ describe PageRecord::PageRecord do
61
129
  expect(subject.new(1)).to respond_to(:stadium)
62
130
  end
63
131
 
132
+ it "returns all current attributes" do
133
+ expect(subject.add_attributes ['more']).to eq ['name', 'points', 'ranking', 'goals', 'country', 'stadium', 'more' ]
134
+ end
135
+
136
+
64
137
  end
65
138
 
66
139
 
67
140
 
68
- describe ".page=" do
69
- before do
70
- PageRecord::PageRecord.page = nil # reset for the spec
71
- end
72
141
 
73
- subject {PageRecord::PageRecord.page = page }
142
+ describe ".page" do
74
143
 
75
- it "sets the page when called on PageRecord::PageRecord" do
76
- expect{PageRecord::PageRecord.page = page}.to change{PageRecord::PageRecord.page}.from(nil).to(page)
77
- end
144
+ context "with a parameter" do
145
+ let(:test_page) { Object.new}
146
+ subject {PageRecord::Base.page test_page }
78
147
 
79
- it "sets the page when called on subclass" do
80
- expect{TeamPage.page = page}.to change{PageRecord::PageRecord.page}.from(nil).to(page)
81
- end
148
+ it "sets the page when called on PageRecord::Base" do
149
+ expect{subject}.to change{PageRecord::Base.page}.to(test_page)
150
+ end
151
+
152
+ it "sets the page when called on subclass" do
153
+ expect{TeamPage.page test_page}.to change{PageRecord::Base.page}.to(test_page)
154
+ end
155
+ end
156
+
157
+ context "without a parameter" do
158
+ it "gets the page on PageRecord::Base" do
159
+ expect(PageRecord::Base.page).to eq page
160
+ end
161
+
162
+ it "gets the page on subclass" do
163
+ expect(TeamPage.page).to eq page
164
+ end
165
+ end
82
166
 
83
167
 
84
168
  end
85
169
 
86
- describe ".page" do
87
170
 
171
+ describe ".host_class" do
88
172
 
89
- it "gets the page on PageRecord::PageRecord" do
90
- expect(PageRecord::PageRecord.page).to eq page
91
- end
173
+ context "with a parameter" do
92
174
 
93
- it "gets the page on subclass" do
94
- expect(TeamPage.page).to eq page
95
- end
175
+ before do
176
+ class FunnyRecord < PageRecord::Base
177
+ host_class Team
178
+ end
179
+ end
180
+
181
+ # TODO refactor test
182
+ subject {FunnyRecord.new(1) }
183
+
184
+ it "sets the host class" do
185
+ expect(FunnyRecord.host_class).to eq Team
186
+ end
187
+
188
+ it "responds to all attributes of host_class" do
189
+ attributes = [ 'name', 'points', 'ranking', 'goals']
190
+ attributes.each do |attribute|
191
+ expect(subject).to respond_to(attribute)
192
+ end
193
+ end
194
+
195
+ end
196
+
197
+ context "without a parameter" do
198
+
199
+ it "returns the host_class" do
200
+ expect(FunnyRecord.host_class).to eq Team
201
+ end
202
+
203
+ end
96
204
 
97
205
  end
98
206
 
@@ -116,8 +224,6 @@ describe PageRecord::PageRecord do
116
224
  expect( subject.map {|c| c.name}).not_to include('Feijenoord')
117
225
  expect( subject.map {|c| c.name}).to include(*['Ajax', 'PSV'])
118
226
  end
119
-
120
-
121
227
  end
122
228
 
123
229
 
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,7 @@
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
7
  require 'coveralls'
8
8
  Coveralls.wear!
9
+
9
10
  require 'page_record'
10
11
  require 'capybara'
11
12
  require 'capybara/dsl'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-17 00:00:00.000000000 Z
12
+ date: 2013-06-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -119,6 +119,7 @@ files:
119
119
  - .rspec
120
120
  - .travis.yml
121
121
  - .yardopts
122
+ - CHANGES.md
122
123
  - Gemfile
123
124
  - Gemfile.lock
124
125
  - LICENSE.txt
@@ -126,13 +127,13 @@ files:
126
127
  - Rakefile
127
128
  - lib/page_record.rb
128
129
  - lib/page_record/attribute_accessors.rb
130
+ - lib/page_record/base.rb
129
131
  - lib/page_record/class_actions.rb
130
132
  - lib/page_record/class_methods.rb
131
133
  - lib/page_record/cucumber.rb
132
134
  - lib/page_record/errors.rb
133
135
  - lib/page_record/finders.rb
134
136
  - lib/page_record/instance_actions.rb
135
- - lib/page_record/page_record.rb
136
137
  - lib/page_record/rspec.rb
137
138
  - lib/page_record/version.rb
138
139
  - page_record.gemspec
@@ -187,4 +188,3 @@ test_files:
187
188
  - spec/support/views/page-with-single-table-with-3-records.erb
188
189
  - spec/support/views/page-with-two-tables-with-3-records.erb
189
190
  - spec/support/views/page-without-records.erb
190
- has_rdoc: