primedia-endeca_factory 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/endeca_factory.rb +10 -3
- data/spec/endeca_factory_spec.rb +27 -2
- metadata +1 -1
data/lib/endeca_factory.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'endeca'
|
3
|
-
require '
|
3
|
+
require File.join(File.dirname(__FILE__), 'core_ext')
|
4
4
|
|
5
5
|
module Endeca
|
6
6
|
class Factory
|
7
|
-
VERSION = "0.
|
7
|
+
VERSION = "0.3.0"
|
8
8
|
def self.version
|
9
9
|
VERSION
|
10
10
|
end
|
@@ -41,7 +41,14 @@ module Endeca
|
|
41
41
|
def build_from_array(params_array)
|
42
42
|
Endeca::DocumentCollection.new([]).tap do |collection|
|
43
43
|
params_array.map!{|params| build_from_hash(params)}
|
44
|
-
|
44
|
+
|
45
|
+
collection.define_singleton_method(:current_page) {1}
|
46
|
+
collection.define_singleton_method(:documents) {params_array}
|
47
|
+
collection.define_singleton_method(:offset) {0}
|
48
|
+
collection.define_singleton_method(:next_page_params) {'next%20page'}
|
49
|
+
collection.define_singleton_method(:per_page) {params_array.size}
|
50
|
+
collection.define_singleton_method(:total_entries) {params_array.size}
|
51
|
+
collection.define_singleton_method(:total_pages) {1}
|
45
52
|
end
|
46
53
|
end
|
47
54
|
|
data/spec/endeca_factory_spec.rb
CHANGED
@@ -51,7 +51,7 @@ describe Endeca::Factory do
|
|
51
51
|
@object = Endeca::Factory.create(@params, TestDocument)
|
52
52
|
end
|
53
53
|
|
54
|
-
it "creates an Endeca::DocumentCollection" do
|
54
|
+
it "creates an Endeca::DocumentCollection," do
|
55
55
|
@object.should be_a_kind_of(Endeca::DocumentCollection)
|
56
56
|
end
|
57
57
|
|
@@ -62,7 +62,7 @@ describe Endeca::Factory do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
describe "with two hashes" do
|
65
|
+
describe "with two hashes," do
|
66
66
|
before do
|
67
67
|
@params << {:title => "A Title"} << {:title => "Another Title"}
|
68
68
|
@object = Endeca::Factory.create(@params, TestDocument)
|
@@ -78,7 +78,32 @@ describe Endeca::Factory do
|
|
78
78
|
@object.documents.map{|document| document.title}.
|
79
79
|
should == @params.map{|param| param[:title]}
|
80
80
|
end
|
81
|
+
|
82
|
+
describe "#total_pages" do
|
83
|
+
it() {@object.total_pages.should == 1}
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#per_page" do
|
87
|
+
it() {@object.per_page.should == 2}
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#current_page" do
|
91
|
+
it() {@object.current_page.should == 1}
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#total_entries" do
|
95
|
+
it() {@object.total_entries.should == 2}
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#offset" do
|
99
|
+
it() {@object.offset.should == 0}
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#next_page_params" do
|
103
|
+
it() {@object.next_page_params.should == "next%20page"}
|
104
|
+
end
|
81
105
|
end
|
106
|
+
|
82
107
|
end
|
83
108
|
end
|
84
109
|
end
|