Active 0.0.14 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,91 @@
1
+ module Active
2
+ module Services
3
+ class Validators
4
+
5
+ STATES = [
6
+ [ "Alabama", "AL" ],
7
+ [ "Alaska", "AK" ],
8
+ [ "Arizona", "AZ" ],
9
+ [ "Arkansas", "AR" ],
10
+ [ "California", "CA" ],
11
+ [ "Colorado", "CO" ],
12
+ [ "Connecticut", "CT" ],
13
+ [ "Delaware", "DE" ],
14
+ [ "District Of Columbia", "DC" ],
15
+ [ "Florida", "FL" ],
16
+ [ "Georgia", "GA" ],
17
+ [ "Hawaii", "HI" ],
18
+ [ "Idaho", "ID" ],
19
+ [ "Illinois", "IL" ],
20
+ [ "Indiana", "IN" ],
21
+ [ "Iowa", "IA" ],
22
+ [ "Kansas", "KS" ],
23
+ [ "Kentucky", "KY" ],
24
+ [ "Louisiana", "LA" ],
25
+ [ "Maine", "ME" ],
26
+ [ "Maryland", "MD" ],
27
+ [ "Massachusetts", "MA" ],
28
+ [ "Michigan", "MI" ],
29
+ [ "Minnesota", "MN" ],
30
+ [ "Mississippi", "MS" ],
31
+ [ "Missouri", "MO" ],
32
+ [ "Montana", "MT" ],
33
+ [ "Nebraska", "NE" ],
34
+ [ "Nevada", "NV" ],
35
+ [ "New Hampshire", "NH" ],
36
+ [ "New Jersey", "NJ" ],
37
+ [ "New Mexico", "NM" ],
38
+ [ "New York", "NY" ],
39
+ [ "North Carolina", "NC" ],
40
+ [ "North Dakota", "ND" ],
41
+ [ "Ohio", "OH" ],
42
+ [ "Oklahoma", "OK" ],
43
+ [ "Oregon", "OR" ],
44
+ [ "Pennsylvania", "PA" ],
45
+ [ "Rhode Island", "RI" ],
46
+ [ "South Carolina", "SC" ],
47
+ [ "South Dakota", "SD" ],
48
+ [ "Tennessee", "TN" ],
49
+ [ "Texas", "TX" ],
50
+ [ "Utah", "UT" ],
51
+ [ "Vermont", "VT" ],
52
+ [ "Virginia", "VA" ],
53
+ [ "Washington", "WA" ],
54
+ [ "West Virginia", "WV" ],
55
+ [ "Wisconsin", "WI" ],
56
+ [ "Wyoming", "WY" ]
57
+ ]
58
+
59
+ def self.full_name(abbr)
60
+ STATES.find do |i|
61
+ if i[1] == abbr.upcase
62
+ return i[0]
63
+ end
64
+ end
65
+ return nil
66
+ end
67
+
68
+ def self.valid_state(name)
69
+ STATES.find do |i|
70
+ if i[0].upcase==name.strip.upcase
71
+ return i[0]
72
+ elsif i[1] == name.upcase
73
+ return i[0]
74
+ end
75
+ end
76
+ return nil
77
+ end
78
+
79
+ # clean zip
80
+ # (http://geekswithblogs.net/MainaD/archive/2007/12/03/117321.aspx)
81
+ def self.valid_zip(zip)
82
+ if zip!="00000" && zip.to_s.strip=~/(^\d{5}(-\d{4})?$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)/
83
+ return zip.to_s.strip
84
+ else
85
+ return nil
86
+ end
87
+ end
88
+ end
89
+
90
+ end
91
+ end
data/spec/Active_spec.rb CHANGED
@@ -1,6 +1,29 @@
1
-
1
+ # Require the spec helper relative to this file
2
2
  require File.join(File.dirname(__FILE__), %w[spec_helper])
3
+ require File.join(File.dirname(__FILE__), %w[custom_matchers_spec])
4
+ require File.join(File.dirname(__FILE__), %w[ .. lib services search])
5
+ require File.join(File.dirname(__FILE__), %w[ .. lib services activity])
6
+ include Active
7
+ include Active::Services
8
+
3
9
 
4
10
  describe Active do
11
+
12
+ it "shouls set memcache" do
13
+ Active.CACHE.should be_nil
14
+ Active.memcache_host "localhost:11211"
15
+ Active.CACHE.should_not be_nil
16
+ end
17
+
18
+ it "should have a working memcache" do
19
+ Active.memcache_host "localhost:11211"
20
+ Active.CACHE.set("active","rocks");
21
+ Active.CACHE.get("active").should eql("rocks")
22
+ end
23
+
24
+ it "should cache the data" do
25
+ Active.memcache_host "localhost:11211"
26
+ end
27
+
5
28
  end
6
29
 
@@ -26,7 +26,7 @@ describe ActiveWorks do
26
26
  end
27
27
  it "should have an address Hash" do
28
28
  a = ActiveWorks.find_by_id(@valid_id)
29
- a.address.should be_an_instance_of(Hash)
29
+ a.address.should be_an_instance_of(HashWithIndifferentAccess)
30
30
  end
31
31
  it "should have a desc" do
32
32
  a = ActiveWorks.find_by_id(@valid_id)
@@ -8,180 +8,111 @@ require File.join(File.dirname(__FILE__), %w[ .. lib services IActivity])
8
8
  include Active::Services
9
9
 
10
10
  describe Activity do
11
- before(:each) do
12
- @valid_attributes = {
13
- :title => "<b>2011 Walt Disney World\xAE Marathon \u003cb\u003e...\u003c/b\u003e | Lake Buena Vista, Florida <b>...</b>",
14
- :url => "http://www.active.com/running/lake-buena-vista-fl/walt-disney-world-marathon-2011",
15
- :language => "en",
16
- :meta => {
17
- :trackbackurl => "http://www.active.com/running/lake-buena-vista-fl/walt-disney-world-marathon-2011",
18
- :substitutionUrl => "1820830",
19
- :assetId => ['3584C7D6-14FD-4FD1-BD07-C2A9B2925B6C','3584c7d6-14fd-4fd1-bd07-c2a9b2925b6c'],
20
- :channel => ['action_sports','running'],
21
- :city => "Lake Buena Vista",
22
- :latitude => "28.39494",
23
- :category => "Activities",
24
- :zip => "32830",
25
- :eventId => "1820830",
26
- :eventLongitude => "-81.56783",
27
- :location => "Walt Disney World Resort",
28
- :eventDate => "2011-01-09T05:40:00-08:00",
29
- :country => 'United States',
30
- :participationCriteria => 'Adult',
31
- :locationName => "Walt Disney World Resort",
32
- :sortDate => "2001-01-09",
33
- :lastModifiedDate => "2010-08-17",
34
- :image1 => 'http://www.active.com/images/events/hotrace.gif',
35
- :lastModifiedDateTime => "2010-08-17 21:00:03.77",
36
- :eventState => "Florida",
37
- :contactPhone => "407-938-3398",
38
- :startDate => "2011-01-09",
39
- :onlineDonationAvailable => "true",
40
- :assetTypeId => "3BF82BBE-CF88-4E8C-A56F-78F5CE87E4C6",
41
- :UpdateDateTime => "8/18/2010 10:16:26 AM",
42
- :contactEmail => 'wdw.sports.marathon.endurance@disneysports.com',
43
- :longitude => "-81.56783",
44
- :description => "This is the description",
45
- :startTime => "5:40:00",
46
- :endTime => "5:40:00",
47
- :eventZip => "32830",
48
- :onlineRegistrationAvailable => "true",
49
- :onlineMembershipAvailable => "false",
50
- :endDate => "2011-01-09",
51
- :keywords => "Event",
52
- :eventLatitude => "28.39494",
53
- :state => "Florida"
54
- },
55
- :escapedUrl => 'http://www.active.com/running/lake-buena-vista-fl/walt-disney-world-marathon-2011',
56
- :summary => "This is the summary."
57
- }
58
- end
59
-
60
- it "should strip out html from the title" do
61
- pending
62
- a = Activity.new(@valid_attributes)
63
- a.title.should eql("2011 Walt Disney World Marathon")
64
- end
65
-
66
- it "should strip out unicode from the title"
67
-
68
- it "should use the first group if title contains pipes."
69
-
70
- it "should have 2 channels" do
71
- a = Activity.new(@valid_attributes)
72
- a.categories.should be_an_instance_of(Array)
73
- a.should have(2).categories
74
- end
75
-
76
- it "should be a valid activity" do
77
- a = Activity.new(@valid_attributes)
78
- a.url.should eql("http://www.active.com/running/lake-buena-vista-fl/walt-disney-world-marathon-2011")
79
- a.categories.include?("action_sports").should be_true
80
- a.asset_id.should eql("3584C7D6-14FD-4FD1-BD07-C2A9B2925B6C")
81
-
82
- a.title.should_not be_nil
83
- a.start_date.should_not be_nil
84
- a.end_date.should_not be_nil
85
- a.categories.should_not be_nil
86
- a.desc.should_not be_nil
87
- a.start_time.should_not be_nil
88
- a.end_time.should_not be_nil
89
-
90
- a.start_date.should be_a_kind_of(Date)
91
- a.end_date.should be_a_kind_of(Date)
92
-
93
- a.address.should_not be_nil
94
- a.address[:city].should_not be_nil
95
- a.address[:state].should_not be_nil
96
- a.address[:country].should_not be_nil
97
- a.address[:zip].should_not be_nil
98
- a.address[:lat].should_not be_nil
99
- a.address[:lng].should_not be_nil
100
- a.address[:name].should_not be_nil
101
- end
102
-
103
- describe "Activity url" do
104
- it "should have a valid seo url: type 1" do
105
- a = Activity.new({ :url => "http://active.com/foo.php", :meta => { :trackbackurl => "http://active.com/running/funrun", :seourl => "http://foo" } })
106
- a.url.should == "http://active.com/running/funrun"
11
+ describe "Creating an activity from a GSA object" do
12
+ before(:each) do
13
+ @a = Activity.new( GSA.new(JSON.parse('{"escapedUrl":"http://www.active.com/triathlon/oceanside-ca/rohto-ironman-703-california-2011","language":"en","title":"2011 Rohto Ironman 70.3 California | Oceanside, California \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/triathlon/oceanside-ca/rohto-ironman-703-california-2011","summary":"","meta":{"eventDate":"2011-04-02T00:00:00-07:00","location":"Oceanside Harbor","tag":["event:10","Triathlon:10"],"eventLongitude":"-117.3586","endDate":"2011-04-02","locationName":"Oceanside Harbor","lastModifiedDateTime":"2010-09-30 06:16:05.107","splitMediaType":["Event","Ironman","Long Course"],"endTime":"0:00:00","city":"Oceanside","google-site-verification":"","startTime":"0:00:00","eventId":"1838902","description":"","longitude":"-117.3586","substitutionUrl":"1838902","sortDate":"2001-04-02","eventState":"California","eventLatitude":"33.19783","keywords":"Event","eventAddress":"1540 Harbor Drive North","dma":"San Diego","seourl":"http://www.active.com/triathlon/oceanside-ca/rohto-ironman-703-california-2011","country":"United States","category":"Activities","market":"San Diego","contactName":"World Triathlon Corporation","assetTypeId":"3BF82BBE-CF88-4E8C-A56F-78F5CE87E4C6","eventZip":"92054","UpdateDateTime":"9/22/2010 11:46:24 AM","latitude":"33.19783","startDate":"2011-04-02","state":"California","mediaType":["Event","Event\\Ironman","Event\\Long Course"],"estParticipants":"2500","assetId":["77ACABBD-BA83-4C78-925D-CE49DEDDF20C","77acabbd-ba83-4c78-925d-ce49deddf20c"],"participationCriteria":"All","onlineDonationAvailable":"0","assetName":["2011 Rohto Ironman 70.3 California","2011 Rohto Ironman 70.3 California"],"zip":"92054","eventURL":"http://www.ironmancalifornia.com/","contactPhone":"813-868-5940","contactEmail":"california70.3@ironman.com","onlineMembershipAvailable":"0","trackbackurl":"http://www.active.com/triathlon/oceanside-ca/rohto-ironman-703-california-2011","onlineRegistrationAvailable":"true","image1":"http://www.active.com/images/events/hotrace.gif","lastModifiedDate":"2010-09-30","channel":"Triathlon"}}')) )
107
14
  end
108
- it "should have a valid seo url: type 2" do
109
- a = Activity.new({ :url => "http://active.com/foo.php", :meta => { :trackbackurl => "http://active.com/running/funrun" } })
110
- a.url.should == "http://active.com/running/funrun"
15
+ it "should have asset ids" do
16
+ @a.asset_id.should_not be_nil
17
+ @a.asset_id.should eql("77ACABBD-BA83-4C78-925D-CE49DEDDF20C")
18
+ @a.asset_type_id.should_not be_nil
19
+ @a.asset_type_id.should eql("3BF82BBE-CF88-4E8C-A56F-78F5CE87E4C6")
20
+ end
21
+ it "should have a title" do
22
+ g = GSA.new(JSON.parse('{"title":"2011 Rohto Ironman 70.3 California\u003cb\u003e...\u003c/b\u003e | Oceanside, California \u003cb\u003e...\u003c/b\u003e"}'))
23
+ g.source.should eql(:gsa)
24
+ g.title.should eql("2011 Rohto Ironman 70.3 California")
25
+ a = Activity.new( g )
26
+ a.gsa.should_not be_nil
27
+ a.title.should eql("2011 Rohto Ironman 70.3 California")
111
28
  end
112
- it "should have a valid seo url: type 3" do
113
- a = Activity.new({ :url => "http://active.com/foo.php" })
114
- a.url.should == "http://active.com/foo.php"
29
+ # start date
30
+ it "should have a valid start date" do
31
+ @a.start_date.should_not be_nil
32
+ @a.start_date.should be_an_instance_of(DateTime)
115
33
  end
116
- end
117
-
118
- describe "ATS data fetch" do
119
- it "should retrive the ats data"
120
- it "should store the date when ats was"
121
- end
122
-
123
- describe "ActiveNet data fetch" do
124
- # todo get a list of ActiveNet ids
125
- # assetTypeId: FB27C928-54DB-4ECD-B42F-482FC3C8681F
126
- # assetTypeName: ActiveNet
127
- # assetId: 4C2C70F1-9D53-4ECA-A04C-68A76C3A53F4
128
- # assetId: 34DB5609-6697-400D-8C52-0305D479C9C1
129
- # assetId: 65B56E1A-5C3E-4D9B-8EA6-0417C07E5956
130
-
131
-
132
- it "should retrive data from ActiveNet" do
133
- # a = Activity.new({})
134
- # a.should receive al call to a.get_ats_data
135
- # a.rawdata.should be a freaking hash
136
- pending
34
+ it "should have nil is no date" do
35
+ a = Activity.new( GSA.new(JSON.parse('{"title":"Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs | Calabasas, California 91302 \u003cb\u003e...\u003c/b\u003e"}')) )
36
+ a.start_date.should be_nil
137
37
  end
138
-
139
- describe "Lazy loading of params" do
140
- it "should call ATS when only asset_id is set" do
141
- ATS.should_receive(:find_by_id).with("A9EF9D79-F859-4443-A9BB-91E1833DF2D5").once
142
- a = Activity.find_by_asset_id(:asset_id => "A9EF9D79-F859-4443-A9BB-91E1833DF2D5")
143
- end
144
- it "should save the asset_id" do
145
- a = Activity.find_by_asset_id(:asset_id => "A9EF9D79-F859-4443-A9BB-91E1833DF2D5")
146
- a.asset_id.should == "A9EF9D79-F859-4443-A9BB-91E1833DF2D5"
147
- a.title.should == "Fitness, Pilates Mat Class (16 Yrs. &amp; Up)"
148
- end
149
- it "should thorw an ActivityFindError if no record is found" do
150
- lambda { Activity.find_by_asset_id( :asset_id => "666" ) }.should raise_error(ActivityFindError)
151
- end
152
-
153
-
154
- it "should save the asset_id and type" do
155
- pending
156
- # a = Activity.find_by_asset_id(:asset_id => "A9EF9D79-F859-4443-A9BB-91E1833DF2D5", :asset_type_id => "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65")
157
- # a.asset_id.should == "A9EF9D79-F859-4443-A9BB-91E1833DF2D5"
158
- # a.asset_type_id.should == "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65"
159
- end
160
- it "should obtain the asset_type_id if it wasn't provided" do
161
- a = Activity.find_by_asset_id(:asset_id => "A9EF9D79-F859-4443-A9BB-91E1833DF2D5")
162
- a.asset_type_id.should == "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65"
163
- end
164
- it "should have an event closing date" do
165
- # a.eventCloseDate.should == "2010-09-13T00:00:00-07:00"
166
- end
167
- it "should return the start time" do
168
- # mock
169
- # a = Activity.new({})
170
- # a.start_time.should == 11:00 am
171
- pending
172
- end
173
- end
174
- end
175
-
176
-
177
- end
178
-
179
-
180
-
181
-
182
-
183
-
184
-
38
+ # end date
39
+ it "should have a valid end date" do
40
+ @a.end_date.should_not be_nil
41
+ @a.end_date.should be_an_instance_of(DateTime)
42
+ end
43
+ it "should have nil is no date" do
44
+ a = Activity.new( GSA.new(JSON.parse('{"title":"Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs | Calabasas, California 91302 \u003cb\u003e...\u003c/b\u003e"}')) )
45
+ a.end_date.should be_nil
46
+ end
47
+ # start time
48
+ it "should have a valid start date" do
49
+ @a.start_time.should_not be_nil
50
+ @a.start_time.should be_an_instance_of(DateTime)
51
+ end
52
+ it "should have nil is no date" do
53
+ g = GSA.new(JSON.parse('{"title":"Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs | Calabasas, California 91302 \u003cb\u003e...\u003c/b\u003e"}'))
54
+ g.start_time.should be_nil
55
+ end
56
+ # end time
57
+ it "should have a valid end date" do
58
+ @a.start_time.should_not be_nil
59
+ @a.start_time.should be_an_instance_of(DateTime)
60
+ end
61
+ it "should have nil is no date" do
62
+ g = GSA.new(JSON.parse('{"title":"Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs | Calabasas, California 91302 \u003cb\u003e...\u003c/b\u003e"}'))
63
+ g.start_time.should be_nil
64
+ end
65
+ # asset_id
66
+ it "should have nil is no date" do
67
+ g = Activity.new GSA.new(JSON.parse('{"title":"Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs | Calabasas, California 91302 \u003cb\u003e...\u003c/b\u003e"}'))
68
+ g.start_time.should be_nil
69
+ end
70
+ it "should have an asset_id" do
71
+ Activity.new(GSA.new).asset_id.should be_nil
72
+ @a.asset_id.should_not be_nil
73
+ end
74
+ it "should have an asset_type_id" do
75
+ Activity.new(GSA.new).asset_type_id.should be_nil
76
+ @a.asset_type_id.should_not be_nil
77
+ end
78
+ #address
79
+ it "should have a full address" do
80
+ g = Activity.new (GSA.new(JSON.parse('{"title":"Calabasas", "meta":{"location":"Oceanside Harbor","eventLongitude":"-117.3586","locationName":"Oceanside Harbor","eventAddress":"1540 Harbor Drive North", "city":"San Diego", "eventState":"CA", "eventZip":"92121", "latitude":"-22", "longitude":"222", "country":"USA" }}')) )
81
+ g.address.should_not be_nil
82
+ g.address[:name].should eql("Oceanside Harbor")
83
+ g.address[:address].should eql("1540 Harbor Drive North")
84
+ g.address[:city].should eql("San Diego")
85
+ g.address[:state].should eql("CA")
86
+ g.address[:zip].should eql("92121")
87
+ g.address[:country].should eql("USA")
88
+ g.address[:lat].should eql("-22")
89
+ g.address[:lng].should eql("222")
90
+ end
91
+ it "should have a partial address that it's full data doesn't live in WORKS or REGCENTER" do
92
+ g = Activity.new(GSA.new(JSON.parse('{"language":"en", "title":"Zumba Punch Card (Adult) - Oct. (5) | Vista, CA, 92084 |", "url":"http://www.active.com/community-services-class/vista-ca/zumba-punch-card-adult-oct-5-2010", "escapedUrl":"http://www.active.com/community-services-class/vista-ca/zumba-punch-card-adult-oct-5-2010", "meta":{"city":"Vista", "assetId":"3ae995d9-5c16-4176-b44e-fa0577644ca4", "substitutionUrl":"vistarecreation/registrationmain.sdi?source=showAsset.sdi&activity_id=4900", "trackbackurl":"http://www.active.com/community-services-class/vista-ca/zumba-punch-card-adult-oct-5-2010", "onlineRegistrationAvailable":"false", "zip":"92084", "sortDate":"2000-10-02", "category":"Activities", "latitude":"33.2000368", "dma":"San Diego", "lastModifiedDate":"2010-09-29", "tags":"2348.321", "lastModifiedDateTime":"2010-09-29 16:46:43.33", "country":"United States of America", "startDate":"2010-10-02", "assetName":"Zumba Punch Card (Adult) - Oct. (5)", "summary":"People of all ages are falling in love with Zumba, one of the fastest growing dance-based fitness crazes in the country. With Zumbas easy-to-follow dance moves you receive body beautifying benefits while enjoying Latin rhythms including Salsa, Meringue, Cumbia, Reggaeton, even belly dance and hip-hop. Zumba is ", "description":"", "seourl":"http://www.active.com/community-services-class/vista-ca/zumba-punch-card-adult-oct-5-2010", "channel":"Community Services", "splitMediaType":"Class", "mediaType":"Class", "longitude":"-117.2425355", "UpdateDateTime":"8/20/2008 9:03:50 AM", "assetTypeId":"FB27C928-54DB-4ECD-B42F-482FC3C8681F", "state":"California", "keywords":""}, "summary":""}')))
93
+ g.address[:name].should be_nil # eql("City of Vista Recreation")
94
+ g.address[:address].should be_nil # eql("200 Civic Center Dr.")
95
+ g.address[:city].should eql("Vista")
96
+ g.address[:state].should eql("California")
97
+ g.address[:zip].should eql("92084")
98
+ g.address[:country].should eql("United States of America")
99
+ g.address[:lat].should eql("33.2000368")
100
+ g.address[:lng].should eql("-117.2425355")
101
+ end
102
+ # TODO FIND OUT WHERE THIS DATA COMES FROM AND GET IT WORKING
103
+ # it "should have a partial address that it's full data doesn't live in WORKS or REGCENTER" do
104
+ # g = Activity.new(GSA.new(JSON.parse('{"language":"en", "title":"Zumba Punch Card (Adult) - Oct. (5) | Vista, CA, 92084 |", "url":"http://www.active.com/community-services-class/vista-ca/zumba-punch-card-adult-oct-5-2010", "escapedUrl":"http://www.active.com/community-services-class/vista-ca/zumba-punch-card-adult-oct-5-2010", "meta":{"city":"Vista", "assetId":"3ae995d9-5c16-4176-b44e-fa0577644ca4", "substitutionUrl":"vistarecreation/registrationmain.sdi?source=showAsset.sdi&activity_id=4900", "trackbackurl":"http://www.active.com/community-services-class/vista-ca/zumba-punch-card-adult-oct-5-2010", "onlineRegistrationAvailable":"false", "zip":"92084", "sortDate":"2000-10-02", "category":"Activities", "latitude":"33.2000368", "dma":"San Diego", "lastModifiedDate":"2010-09-29", "tags":"2348.321", "lastModifiedDateTime":"2010-09-29 16:46:43.33", "country":"United States of America", "startDate":"2010-10-02", "assetName":"Zumba Punch Card (Adult) - Oct. (5)", "summary":"People of all ages are falling in love with Zumba, one of the fastest growing dance-based fitness crazes in the country. With Zumbas easy-to-follow dance moves you receive body beautifying benefits while enjoying Latin rhythms including Salsa, Meringue, Cumbia, Reggaeton, even belly dance and hip-hop. Zumba is ", "description":"", "seourl":"http://www.active.com/community-services-class/vista-ca/zumba-punch-card-adult-oct-5-2010", "channel":"Community Services", "splitMediaType":"Class", "mediaType":"Class", "longitude":"-117.2425355", "UpdateDateTime":"8/20/2008 9:03:50 AM", "assetTypeId":"FB27C928-54DB-4ECD-B42F-482FC3C8681F", "state":"California", "keywords":""}, "summary":""}')))
105
+ # g.address[:name].should eql("City of Vista Recreation")
106
+ # g.address[:address].should eql("200 Civic Center Dr.")
107
+ # g.address[:city].should eql("Vista")
108
+ # g.address[:state].should eql("California")
109
+ # g.address[:zip].should eql("92084")
110
+ # g.address[:country].should eql("United States of America")
111
+ # g.address[:lat].should eql("33.2000368")
112
+ # g.address[:lng].should eql("-117.2425355")
113
+ # end
185
114
 
186
115
 
187
116
 
117
+ end
118
+ end
data/spec/ats_spec.rb CHANGED
@@ -4,11 +4,13 @@ require File.join(File.dirname(__FILE__), %w[custom_matchers_spec])
4
4
  require File.join(File.dirname(__FILE__), %w[ .. lib services search])
5
5
  require File.join(File.dirname(__FILE__), %w[ .. lib services activity])
6
6
  require File.join(File.dirname(__FILE__), %w[ .. lib services ats])
7
+ require File.join(File.dirname(__FILE__), %w[ .. lib services address])
7
8
  include Active::Services
8
9
 
9
10
  describe ATS do
10
11
  before(:each) do
11
- @valid_id = "A9EF9D79-F859-4443-A9BB-91E1833DF2D5"
12
+ # @valid_id = "A9EF9D79-F859-4443-A9BB-91E1833DF2D5"
13
+ @valid_id="61BB7D71-EC01-46B8-A601-38CA1C9AE893"
12
14
  @reg_center_id = "D9A22F33-8A14-4175-8D5B-D11578212A98"
13
15
  end
14
16
  it "should set find by id" do
@@ -42,7 +44,7 @@ describe ATS do
42
44
  end
43
45
  it "should have an address Hash" do
44
46
  a = ATS.find_by_id(@valid_id)
45
- a.address.should be_an_instance_of(Hash)
47
+ a.address.should be_an_instance_of(HashWithIndifferentAccess)
46
48
  end
47
49
  it "should have a startDate Date" do
48
50
  a = ATS.find_by_id(@valid_id)
@@ -52,6 +54,10 @@ describe ATS do
52
54
  a = ATS.find_by_id(@valid_id)
53
55
  a.title.should be_an_instance_of(String)
54
56
  end
55
-
57
+ ##########
58
+ it "should have an address" do
59
+ a = ATS.new('<importSource><asset row="1" destinationID=""><isSearchable>true</isSearchable><assetTypeId>FB27C928-54DB-4ECD-B42F-482FC3C8681F</assetTypeId><substitutionUrl>vistarecreation/registrationmain.sdi?source=showAsset.sdi&amp;activity_id=4900</substitutionUrl><assetName>Zumba Punch Card (Adult) - Oct. (5)</assetName><category>Activities</category><channel>Community Services</channel><mediaType>Class</mediaType><searchWeight>1</searchWeight><summary>People of all ages are falling in love with Zumba, one of the fastest growing dance-based fitness crazes in the country. With Zumbas easy-to-follow dance moves you receive body beautifying benefits while enjoying Latin rhythms including Salsa, Meringue, Cumbia, Reggaeton, even belly dance and hip-hop. Zumba is sure to put the fun back into your work outs!</summary><zip>92084</zip><city>Vista</city><state>California</state><country>United States of America</country><startDate>2010-10-02</startDate><onlineRegistrationAvailable>false</onlineRegistrationAvailable><tags>2348.321</tags><assetId>3ae995d9-5c16-4176-b44e-fa0577644ca4</assetId><trackbackurl>http://www.active.com/page/event_details_an.htm?type=activenet&amp;subUrl=vistarecreation/registrationmain.sdi?source=showAsset.sdi&amp;activity_id=4900</trackbackurl><seourl>http://www.active.com/community-services-class/vista-ca/zumba-punch-card-adult-oct-5-2010</seourl><dma>San Diego</dma><longitude>-117.2425355</longitude><latitude>33.2000368</latitude></asset></importSource>')
60
+ a.data.should_not be_nil
61
+ end
56
62
 
57
63
  end
data/spec/gsa_spec.rb ADDED
@@ -0,0 +1,123 @@
1
+ # Require the spec helper relative to this file
2
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
3
+ require File.join(File.dirname(__FILE__), %w[custom_matchers_spec])
4
+ require File.join(File.dirname(__FILE__), %w[ .. lib services search])
5
+ require File.join(File.dirname(__FILE__), %w[ .. lib services activity])
6
+ require File.join(File.dirname(__FILE__), %w[ .. lib services reg_center])
7
+ require File.join(File.dirname(__FILE__), %w[ .. lib services address])
8
+ include Active::Services
9
+ # EFF92D9D-D487-4FBD-A879-38B3D3BBC8CD
10
+ describe GSA do
11
+ before(:each) do
12
+ @a = GSA.new(JSON.parse('{"escapedUrl":"http://www.active.com/triathlon/oceanside-ca/rohto-ironman-703-california-2011","language":"en","title":"2011 Rohto Ironman 70.3 California | Oceanside, California \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/triathlon/oceanside-ca/rohto-ironman-703-california-2011","summary":"","meta":{"eventDate":"2011-04-02T00:00:00-07:00","location":"Oceanside Harbor","tag":["event:10","Triathlon:10"],"eventLongitude":"-117.3586","endDate":"2011-04-02","locationName":"Oceanside Harbor","lastModifiedDateTime":"2010-09-30 06:16:05.107","splitMediaType":["Event","Ironman","Long Course"],"endTime":"0:00:00","city":"Oceanside","google-site-verification":"","startTime":"0:00:00","eventId":"1838902","description":"","longitude":"-117.3586","substitutionUrl":"1838902","sortDate":"2001-04-02","eventState":"California","eventLatitude":"33.19783","keywords":"Event","eventAddress":"1540 Harbor Drive North","dma":"San Diego","seourl":"http://www.active.com/triathlon/oceanside-ca/rohto-ironman-703-california-2011","country":"United States","category":"Activities","market":"San Diego","contactName":"World Triathlon Corporation","assetTypeId":"3BF82BBE-CF88-4E8C-A56F-78F5CE87E4C6","eventZip":"92054","UpdateDateTime":"9/22/2010 11:46:24 AM","latitude":"33.19783","startDate":"2011-04-02","state":"California","mediaType":["Event","Event\\Ironman","Event\\Long Course"],"estParticipants":"2500","assetId":["77ACABBD-BA83-4C78-925D-CE49DEDDF20C","77acabbd-ba83-4c78-925d-ce49deddf20c"],"participationCriteria":"All","onlineDonationAvailable":"0","assetName":["2011 Rohto Ironman 70.3 California","2011 Rohto Ironman 70.3 California"],"zip":"92054","eventURL":"http://www.ironmancalifornia.com/","contactPhone":"813-868-5940","contactEmail":"california70.3@ironman.com","onlineMembershipAvailable":"0","trackbackurl":"http://www.active.com/triathlon/oceanside-ca/rohto-ironman-703-california-2011","onlineRegistrationAvailable":"true","image1":"http://www.active.com/images/events/hotrace.gif","lastModifiedDate":"2010-09-30","channel":"Triathlon"}}'))
13
+ end
14
+ it "should have asset ids" do
15
+ @a.asset_id.should_not be_nil
16
+ @a.asset_type_id.should_not be_nil
17
+ end
18
+ # TITLE
19
+ it "should have a clean title" do
20
+ @a.title.should_not be_nil
21
+ @a.title.should eql("2011 Rohto Ironman 70.3 California")
22
+ end
23
+ it "should have a clean title" do
24
+ g = GSA.new(JSON.parse('{"title":"2011 Rohto Ironman 70.3 California\u003cb\u003e...\u003c/b\u003e | Oceanside, California \u003cb\u003e...\u003c/b\u003e"}'))
25
+ g.title.should eql("2011 Rohto Ironman 70.3 California")
26
+ g = GSA.new(JSON.parse('{"title":"Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs | Calabasas, California 91302 \u003cb\u003e...\u003c/b\u003e"}'))
27
+ g.title.should eql("Calabasas Classic 2010 - 5k 10k Runs")
28
+ end
29
+ it "should have a nil title" do
30
+ GSA.new({}).title.should be_nil
31
+ end
32
+ # start date
33
+ it "should have a valid start date" do
34
+ @a.start_date.should_not be_nil
35
+ @a.start_date.should be_an_instance_of(DateTime)
36
+ end
37
+ it "should have nil is no date" do
38
+ g = GSA.new(JSON.parse('{"title":"Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs | Calabasas, California 91302 \u003cb\u003e...\u003c/b\u003e"}'))
39
+ g.start_date.should be_nil
40
+ end
41
+ # end date
42
+ it "should have a valid end date" do
43
+ @a.end_date.should_not be_nil
44
+ @a.end_date.should be_an_instance_of(DateTime)
45
+ end
46
+ it "should have nil is no date" do
47
+ g = GSA.new(JSON.parse('{"title":"Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs | Calabasas, California 91302 \u003cb\u003e...\u003c/b\u003e"}'))
48
+ g.end_date.should be_nil
49
+ end
50
+ # start time
51
+ it "should have a valid start date" do
52
+ @a.start_time.should_not be_nil
53
+ @a.start_time.should be_an_instance_of(DateTime)
54
+ end
55
+ it "should have nil is no date" do
56
+ g = GSA.new(JSON.parse('{"title":"Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs | Calabasas, California 91302 \u003cb\u003e...\u003c/b\u003e"}'))
57
+ g.start_time.should be_nil
58
+ end
59
+ # end time
60
+ it "should have a valid end date" do
61
+ @a.start_time.should_not be_nil
62
+ @a.start_time.should be_an_instance_of(DateTime)
63
+ end
64
+ it "should have nil is no date" do
65
+ g = GSA.new(JSON.parse('{"title":"Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs | Calabasas, California 91302 \u003cb\u003e...\u003c/b\u003e"}'))
66
+ g.start_time.should be_nil
67
+ end
68
+ it "should have an asset_id" do
69
+ GSA.new().asset_id.should be_nil
70
+ @a.asset_id.should_not be_nil
71
+ end
72
+ it "should have an asset_type_id" do
73
+ GSA.new().asset_type_id.should be_nil
74
+ @a.asset_type_id.should_not be_nil
75
+ end
76
+ # substitutionUrl
77
+ it "should have an id for substitutionUrl" do
78
+ @a.substitutionUrl.should eql("1838902")
79
+ g = GSA.new(JSON.parse('{"title":"Calabasas", "meta":{"substitutionUrl":"vistarecreation/registrationmain.sdi?source=showAsset.sdi&activity_id=4900"}}'))
80
+ g.substitutionUrl.should eql("4900")
81
+ end
82
+ # bounding_box
83
+ it "should raise an error with a bad bounding box" do
84
+ lambda {s = Search.search({ :bounding_box => { :sw => "37.695141,-123.013657"}}) }.should raise_error(RuntimeError)
85
+ end
86
+ it "should search a bounding box String" do
87
+ s = Search.search({ :bounding_box => { :sw => "37.695141,-123.013657", :ne => "37.832371,-122.356979"}})
88
+ r = s.results.first
89
+ r.address["city"].should eql("San Francisco")
90
+ end
91
+ it "should search a bounding box Hash" do
92
+ s = Search.search({ :bounding_box => { :sw => [37.695141, -123.013657], :ne => [37.832371,-122.356979] }})
93
+ r = s.results.first
94
+ r.address["city"].should eql("San Francisco")
95
+ end
96
+
97
+
98
+ # address
99
+ it "should have a full address" do
100
+ g = GSA.new(JSON.parse('{"title":"Calabasas", "meta":{"location":"Oceanside Harbor","eventLongitude":"-117.3586","locationName":"Oceanside Harbor","eventAddress":"1540 Harbor Drive North", "city":"San Diego", "eventState":"CA", "eventZip":"92121", "latitude":"-22", "longitude":"222", "country":"USA" }}'))
101
+ g.address.should_not be_nil
102
+ g.address[:name].should eql("Oceanside Harbor")
103
+ g.address[:address].should eql("1540 Harbor Drive North")
104
+ g.address[:city].should eql("San Diego")
105
+ g.address[:state].should eql("CA")
106
+ g.address[:zip].should eql("92121")
107
+ g.address[:country].should eql("USA")
108
+ g.address[:lat].should eql("-22")
109
+ g.address[:lng].should eql("222")
110
+ end
111
+ it "should have a partial address" do
112
+ g = GSA.new(JSON.parse('{"language":"en", "title":"Zumba Punch Card (Adult) - Oct. (5) | Vista, CA, 92084 |", "url":"http://www.active.com/community-services-class/vista-ca/zumba-punch-card-adult-oct-5-2010", "escapedUrl":"http://www.active.com/community-services-class/vista-ca/zumba-punch-card-adult-oct-5-2010", "meta":{"city":"Vista", "assetId":"3ae995d9-5c16-4176-b44e-fa0577644ca4", "substitutionUrl":"vistarecreation/registrationmain.sdi?source=showAsset.sdi&activity_id=4900", "trackbackurl":"http://www.active.com/community-services-class/vista-ca/zumba-punch-card-adult-oct-5-2010", "onlineRegistrationAvailable":"false", "zip":"92084", "sortDate":"2000-10-02", "category":"Activities", "latitude":"33.2000368", "dma":"San Diego", "lastModifiedDate":"2010-09-29", "tags":"2348.321", "lastModifiedDateTime":"2010-09-29 16:46:43.33", "country":"United States of America", "startDate":"2010-10-02", "assetName":"Zumba Punch Card (Adult) - Oct. (5)", "summary":"People of all ages are falling in love with Zumba, one of the fastest growing dance-based fitness crazes in the country. With Zumbas easy-to-follow dance moves you receive body beautifying benefits while enjoying Latin rhythms including Salsa, Meringue, Cumbia, Reggaeton, even belly dance and hip-hop. Zumba is ", "description":"", "seourl":"http://www.active.com/community-services-class/vista-ca/zumba-punch-card-adult-oct-5-2010", "channel":"Community Services", "splitMediaType":"Class", "mediaType":"Class", "longitude":"-117.2425355", "UpdateDateTime":"8/20/2008 9:03:50 AM", "assetTypeId":"FB27C928-54DB-4ECD-B42F-482FC3C8681F", "state":"California", "keywords":""}, "summary":""}'))
113
+ g.address[:name].should be_nil
114
+ g.address[:address].should be_nil
115
+ g.address[:city].should eql("Vista")
116
+ g.address[:state].should eql("California")
117
+ g.address[:zip].should eql("92084")
118
+ g.address[:country].should eql("United States of America")
119
+ g.address[:lat].should eql("33.2000368")
120
+ g.address[:lng].should eql("-117.2425355")
121
+ end
122
+
123
+ end