supercamp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,177 @@
1
+ require "spec_helper"
2
+
3
+ describe Supercamp::Criteria::Abstract do
4
+
5
+ describe ".search" do
6
+
7
+ context "Supercamp::Criteria::Campground" do
8
+
9
+ it "returns a Supercamp::Criteria" do
10
+ expect(Supercamp::Criteria::Campground.search {}).to be_instance_of Supercamp::Criteria::Campground
11
+ end
12
+
13
+ context "w/ supplied options" do
14
+
15
+ let :criteria do
16
+ Supercamp::Criteria::Campground.search do
17
+ name "Camp Cool"
18
+ has :pets
19
+ end
20
+ end
21
+
22
+ it "please?" do
23
+ expect(criteria.options).to eq \
24
+ ({ "pname" => "Camp Cool", "pets" => 3010 })
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+
34
+ describe "#options" do
35
+
36
+ it { expect(subject.options).to eq ({}) }
37
+
38
+ end
39
+
40
+
41
+ describe "#search" do
42
+
43
+ context "Supercamp::Criteria::Campground" do
44
+
45
+ subject { Supercamp::Criteria::Campground.new }
46
+
47
+ it "returns a Supercamp::Criteria" do
48
+ expect(subject.search {}).to be_instance_of Supercamp::Criteria::Campground
49
+ end
50
+
51
+ context "w/ supplied options" do
52
+
53
+ let :criteria do
54
+ subject.search do
55
+ name "Camp Cool"
56
+ has :pets
57
+ end
58
+ end
59
+
60
+ it "please?" do
61
+ expect(criteria.options).to eq \
62
+ ({ "pname" => "Camp Cool", "pets" => 3010 })
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ describe "#endpoint" do
72
+ it { expect(subject.endpoint).to eq "http://api.amp.active.com/camping/abstracts" }
73
+ end
74
+
75
+
76
+ describe "#query" do
77
+
78
+ before do
79
+ expect(Supercamp.config).to receive(:api_key).and_return "z"
80
+ end
81
+
82
+ let :base_url do
83
+ "http://api.amp.active.com/camping/abstracts?api_key=z"
84
+ end
85
+
86
+ context "w/ valid single Supercamp::Criteria" do
87
+
88
+ let :criteria do
89
+ subject.tap do |s|
90
+ s.options = { pname: "Jolly Good" }
91
+ end
92
+ end
93
+
94
+ it "creates a Typhoeus::Request" do
95
+ expect(criteria.query).to be_instance_of Typhoeus::Request
96
+ end
97
+
98
+ it "combines options w/ endpoint" do
99
+ expect(criteria.query.url).to eq \
100
+ "#{base_url}&pname=Jolly%20Good"
101
+ end
102
+
103
+ end
104
+
105
+ context "w/ valid multi Supercamp::Criteria" do
106
+
107
+ let :criteria do
108
+ subject.tap do |s|
109
+ s.options = { pname: "Jolly Good", amenity: 4001, water: 3007, pets: 3010 }
110
+ end
111
+ end
112
+
113
+ it "combines options w/ endpoint" do
114
+ expect(criteria.query.url).to eq \
115
+ "#{base_url}&pname=Jolly%20Good&amenity=4001&water=3007&pets=3010"
116
+ end
117
+
118
+ end
119
+
120
+ context "w/ special characters in Supercamp::Criteria" do
121
+
122
+ let :criteria do
123
+ subject.tap do |s|
124
+ s.options = { pname: "$$%So**??Bad" }
125
+ end
126
+ end
127
+
128
+ it "combines options w/ endpoint" do
129
+ expect(criteria.query.url).to eq \
130
+ "#{base_url}&pname=%24%24%25So%2A%2A%3F%3FBad"
131
+ end
132
+ end
133
+
134
+ end
135
+
136
+
137
+ describe "#response" do
138
+
139
+ context "w/ valid response" do
140
+
141
+ subject do
142
+ Supercamp::Criteria::Campground.search do
143
+ state "CA"
144
+ site_type "tent"
145
+ people 4
146
+ end
147
+ end
148
+
149
+ it "returns a Supercamp::Response" do
150
+ VCR.use_cassette("campground ca tent") do
151
+ expect(subject.response).to be_instance_of Supercamp::Response
152
+ end
153
+ end
154
+
155
+ end
156
+
157
+ context "w/ invalid response" do
158
+
159
+ before do
160
+ expect(Supercamp.config).to receive(:api_key).and_return nil
161
+ end
162
+
163
+ subject do
164
+ Supercamp.campgrounds.search.state("CA")
165
+ end
166
+
167
+ it "returns a Supercamp::Error" do
168
+ VCR.use_cassette("campground no api key") do
169
+ expect { subject.response }.to raise_error Supercamp::Error
170
+ end
171
+ end
172
+
173
+ end
174
+
175
+ end
176
+
177
+ end
@@ -0,0 +1,138 @@
1
+ require "spec_helper"
2
+
3
+ describe Supercamp::Criteria::Campground do
4
+
5
+ let :criteria do
6
+ Supercamp::Criteria::Campground.new
7
+ end
8
+
9
+ describe "#endpoint" do
10
+
11
+ it do
12
+ expect(criteria.endpoint).to eq \
13
+ "http://api.amp.active.com/camping/campgrounds"
14
+ end
15
+
16
+ end
17
+
18
+
19
+ describe "#geo" do
20
+
21
+ it "returns Supercamp::Criteria::Campground" do
22
+ expect(criteria.geo(1, 2)).to be_instance_of Supercamp::Criteria::Campground
23
+ end
24
+
25
+ it "sets :landmarkLat & :landmarkLong" do
26
+ expect {
27
+ criteria.geo(1, 2)
28
+ }.to change(criteria, :options).from({}).to({ "landmarkLat" => 1, "landmarkLong" => 2 })
29
+ end
30
+
31
+ end
32
+
33
+
34
+ describe "#state" do
35
+
36
+ it "returns Supercamp::Criteria::Campground" do
37
+ expect(criteria.state("CA")).to be_instance_of Supercamp::Criteria::Campground
38
+ end
39
+
40
+ it "sets :pstate option" do
41
+ expect {
42
+ criteria.state("CA")
43
+ }.to change(criteria, :options).from({}).to({ "pstate" => "CA" })
44
+ end
45
+
46
+ end
47
+
48
+
49
+ describe "#name" do
50
+
51
+ it "returns Supercamp::Criteria::Campground" do
52
+ expect(criteria.name("San Francisco")).to be_instance_of Supercamp::Criteria::Campground
53
+ end
54
+
55
+ it "sets :pname option" do
56
+ expect {
57
+ criteria.name("San Francisco")
58
+ }.to change(criteria, :options).from({}).to({ "pname" => "San Francisco" })
59
+ end
60
+
61
+ end
62
+
63
+
64
+
65
+ describe "#amenity" do
66
+
67
+ it "returns Supercamp::Criteria::Campground" do
68
+ expect(criteria.amenity(:biking)).to be_instance_of Supercamp::Criteria::Campground
69
+ end
70
+
71
+ it "sets :amenity option with code translation" do
72
+ expect {
73
+ criteria.amenity(:biking)
74
+ }.to change(criteria, :options).from({}).to({ "amenity" => 4001 })
75
+ end
76
+
77
+ end
78
+
79
+
80
+ describe "#has" do
81
+
82
+ context "w/ no perk" do
83
+
84
+ it "returns Supercamp::Criteria::Campground" do
85
+ expect(criteria.has).to be_instance_of Supercamp::Criteria::Campground
86
+ end
87
+
88
+ it "sets no options" do
89
+ expect {
90
+ criteria.has
91
+ }.to_not change(criteria, :options).from({})
92
+ end
93
+
94
+ end
95
+
96
+ context "w/ no valid perks" do
97
+
98
+ it "sets no options" do
99
+ expect {
100
+ criteria.has(:boogers)
101
+ }.to_not change(criteria, :options).from({})
102
+ end
103
+
104
+ end
105
+
106
+ context "w/ a single perk" do
107
+
108
+ it "sets 'waterfront' options" do
109
+ expect {
110
+ criteria.has(:waterfront)
111
+ }.to change(criteria, :options).from({}).to({ "waterfront" => 3011 })
112
+ end
113
+
114
+ end
115
+
116
+ context "w/ multiple valid perks" do
117
+
118
+ it "sets 'waterfront' & 'pets' options" do
119
+ expect {
120
+ criteria.has(:waterfront, :pets)
121
+ }.to change(criteria, :options).from({}).to({ "waterfront" => 3011, "pets" => 3010 })
122
+ end
123
+
124
+ end
125
+
126
+ context "w/ multiple valid and invalid perks" do
127
+
128
+ it "sets 'waterfront' & 'pets' options" do
129
+ expect {
130
+ criteria.has(:pets, :cats)
131
+ }.to change(criteria, :options).from({}).to({ "pets" => 3010 })
132
+ end
133
+
134
+ end
135
+
136
+ end
137
+
138
+ end
@@ -0,0 +1,109 @@
1
+ require "spec_helper"
2
+
3
+ describe Supercamp::Criteria::Campsite do
4
+
5
+ let :criteria do
6
+ Supercamp::Criteria::Campsite.new
7
+ end
8
+
9
+ describe "#endpoint" do
10
+
11
+ it do
12
+ expect(criteria.endpoint).to eq \
13
+ "http://api.amp.active.com/camping/campsites"
14
+ end
15
+
16
+ end
17
+
18
+
19
+ describe "#site_type" do
20
+
21
+ it "returns Supercamp::Criteria::Campsite" do
22
+ expect(criteria.site_type(:rv)).to be_instance_of Supercamp::Criteria::Campsite
23
+ end
24
+
25
+ it "sets :siteType option with code translation" do
26
+ expect {
27
+ criteria.site_type(:rv)
28
+ }.to change(criteria, :options).from({}).to({ "siteType" => 2001 })
29
+ end
30
+
31
+ end
32
+
33
+
34
+ describe "#arrival" do
35
+
36
+ it "returns Supercamp::Criteria::Campsite" do
37
+ expect(criteria.arrival("05/08/1981")).to be_instance_of Supercamp::Criteria::Campsite
38
+ end
39
+
40
+ it "sets :arvdate option" do
41
+ expect {
42
+ criteria.arrival("05/08/1981")
43
+ }.to change(criteria, :options).from({}).to({ "arvdate" => "05/08/1981" })
44
+ end
45
+
46
+ end
47
+
48
+
49
+ describe "#nights" do
50
+
51
+ it "returns Supercamp::Criteria::Campsite" do
52
+ expect(criteria.nights(2)).to be_instance_of Supercamp::Criteria::Campsite
53
+ end
54
+
55
+ it "sets :lengthOfStay option" do
56
+ expect {
57
+ criteria.nights(2)
58
+ }.to change(criteria, :options).from({}).to({ "lengthOfStay" => 2 })
59
+ end
60
+
61
+ end
62
+
63
+
64
+ describe "#min_equip_length" do
65
+
66
+ it "returns Supercamp::Criteria::Campsite" do
67
+ expect(criteria.min_equip_length(1)).to be_instance_of Supercamp::Criteria::Campsite
68
+ end
69
+
70
+ it "sets :eqplen option with amount" do
71
+ expect {
72
+ criteria.min_equip_length(61)
73
+ }.to change(criteria, :options).from({}).to({ "eqplen" => 61 })
74
+ end
75
+
76
+ end
77
+
78
+
79
+ describe "#people" do
80
+
81
+ it "returns Supercamp::Criteria::Campsite" do
82
+ expect(criteria.people(15)).to be_instance_of Supercamp::Criteria::Campsite
83
+ end
84
+
85
+ it "sets :people option with amount" do
86
+ expect {
87
+ criteria.people(66)
88
+ }.to change(criteria, :options).from({}).to({ "Maxpeople" => 66 })
89
+ end
90
+
91
+ end
92
+
93
+
94
+ describe "#min_elec_amps" do
95
+
96
+ it "returns Supercamp::Criteria::Campsite" do
97
+ expect(criteria.min_elec_amps(15)).to be_instance_of Supercamp::Criteria::Campsite
98
+ end
99
+
100
+ it "sets :hookup option with code translation" do
101
+ expect {
102
+ criteria.min_elec_amps(15)
103
+ }.to change(criteria, :options).from({}).to({ "hookup" => 3002 })
104
+ end
105
+
106
+ end
107
+
108
+
109
+ end
@@ -0,0 +1,50 @@
1
+ require "spec_helper"
2
+
3
+ describe Supercamp::Criteria::Detail do
4
+
5
+ let :criteria do
6
+ Supercamp::Criteria::Detail.new
7
+ end
8
+
9
+ describe "#endpoint" do
10
+
11
+ it do
12
+ expect(criteria.endpoint).to eq \
13
+ "http://api.amp.active.com/camping/details"
14
+ end
15
+
16
+ end
17
+
18
+
19
+ describe "#contract_code" do
20
+
21
+ it "returns Supercamp::Criteria::Detail" do
22
+ expect(criteria.contract_code("yep")).to \
23
+ be_instance_of Supercamp::Criteria::Detail
24
+ end
25
+
26
+ it "sets contractCode option" do
27
+ expect {
28
+ criteria.contract_code("CA")
29
+ }.to change(criteria, :options).from({}).to({ "contractCode" => "CA" })
30
+ end
31
+
32
+ end
33
+
34
+
35
+ describe "#id" do
36
+
37
+ it "returns Supercamp::Criteria::Detail" do
38
+ expect(criteria.id("yep")).to \
39
+ be_instance_of Supercamp::Criteria::Detail
40
+ end
41
+
42
+ it "sets :parkId option" do
43
+ expect {
44
+ criteria.id("11")
45
+ }.to change(criteria, :options).from({}).to({ "parkId" => "11" })
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,47 @@
1
+ require "spec_helper"
2
+
3
+ describe Supercamp::Error do
4
+
5
+ describe ".new" do
6
+
7
+ context "403 - Forbidden" do
8
+
9
+ before do
10
+ expect(Supercamp.config).to receive(:api_key).and_return nil
11
+ end
12
+
13
+ around(:each) do |example|
14
+ VCR.use_cassette "error 403 forbidden" do
15
+ example.run
16
+ end
17
+ end
18
+
19
+ let :criteria do
20
+ Supercamp.campsites.site_type("rv")
21
+ end
22
+
23
+ subject do
24
+ Supercamp::Error.new criteria, criteria.query.run
25
+ end
26
+
27
+ it "is a Supercamp::Error" do
28
+ expect(subject).to be_instance_of Supercamp::Error
29
+ end
30
+
31
+ it "sets :code" do
32
+ expect(subject.code).to eq 403
33
+ end
34
+
35
+ it "sets :api_code" do
36
+ expect(subject.api_code).to eq "ERR_403_DEVELOPER_INACTIVE"
37
+ end
38
+
39
+ it "sets :message" do
40
+ expect(subject.message).to eq "<h1>403 Developer Inactive</h1>"
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+
3
+ describe Supercamp::Response do
4
+
5
+ describe ".new" do
6
+
7
+ around(:each) do |example|
8
+ VCR.use_cassette "response of limited campground search" do
9
+ example.run
10
+ end
11
+ end
12
+
13
+ let :criteria do
14
+ Supercamp.campgrounds.search do
15
+ site_type "tent"
16
+ state "CA"
17
+ amenity "fishing"
18
+ has "pets", "waterfront"
19
+ end
20
+ end
21
+
22
+ subject do
23
+ Supercamp::Response.new criteria.query.run
24
+ end
25
+
26
+ it "sets :count" do
27
+ expect(subject.count).to eq 21
28
+ end
29
+
30
+ it "sets array to :entries" do
31
+ expect(subject.entries).to be_instance_of Array
32
+ end
33
+
34
+ it "sets 21 entries" do
35
+ expect(subject.entries.size).to eq 21
36
+ end
37
+
38
+ context "first entry" do
39
+
40
+ let(:entry) { subject.entries.first }
41
+
42
+ it "sets Hashr instances" do
43
+ expect(entry).to be_instance_of Hashr
44
+ end
45
+
46
+ it "can access :facility_name" do
47
+ expect(entry.facility_name).to eq "BUSHAY RECREATION AREA"
48
+ expect(entry[:facility_name]).to eq "BUSHAY RECREATION AREA"
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,48 @@
1
+ require "spec_helper"
2
+
3
+ describe Supercamp do
4
+
5
+ describe ".config" do
6
+
7
+ it "require Configuration" do
8
+ expect(Supercamp.config).to be_instance_of Supercamp::Configuration
9
+ end
10
+
11
+ end
12
+
13
+
14
+ describe ".configure" do
15
+
16
+ it "allows options to be set through block" do
17
+ expect(Supercamp.config).to receive(:api_key=).with("yes")
18
+ expect(Supercamp.config).to receive(:timeout=).with(10000)
19
+ Supercamp.configure do |config|
20
+ config.api_key = "yes"
21
+ config.timeout = 10000
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+
28
+ describe ".campsites" do
29
+
30
+ it { expect(Supercamp.campsites).to be_instance_of Supercamp::Criteria::Campsite }
31
+
32
+ end
33
+
34
+
35
+ describe ".campgrounds" do
36
+
37
+ it { expect(Supercamp.campgrounds).to be_instance_of Supercamp::Criteria::Campground }
38
+
39
+ end
40
+
41
+
42
+ describe ".details" do
43
+
44
+ it { expect(Supercamp.details).to be_instance_of Supercamp::Criteria::Detail }
45
+
46
+ end
47
+
48
+ end