-
Notifications
You must be signed in to change notification settings - Fork 1
/
events_helper_spec.rb
164 lines (140 loc) · 5.88 KB
/
events_helper_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
require File.dirname(__FILE__) + '/../spec_helper'
describe EventsHelper do
before(:each) do
@event = Event.make
end
# refactor from list.html.erb_spec into here?
it "should generate an iCal unique id as a String" do
helper.ical_uid(@event).should be_a_kind_of(String)
end
it "should generate a delete link as a String" do
helper.delete_link(@event).should be_a_kind_of(String)
end
it "should generate an edit link as a String" do
helper.edit_link(@event).should be_a_kind_of(String)
end
it "should generate an iCal export link as a String" do
helper.ical_link(@event).should be_a_kind_of(String)
end
it "should generate a map link as a String" do
helper.map_link(@event).should be_a_kind_of(String)
end
it "should generate a microformat HTML date element as a String" do
@event.date = Time.now # arbitrary value
helper.date_element(@event).should be_a_kind_of(String)
end
=begin
#Delete this example and add some real ones or delete this file
it "should include the EventsHelper" do
included_modules = self.metaclass.send :included_modules
included_modules.should include(EventsHelper)
end
=end
it "should generate a comma-separated list of names from an array of users" do
users = (1..5).map{User.make}
names = helper.list_names users
users.each do |user|
names.should include(user.to_s)
end
end
it "should get an attendance status for an event and a user" do
helper.attendance_status(@event, User.make).should == :maybe
end
it "should generate a distance string from an event to a user's coords," do
marnen = User.make(:coords => Point.from_x_y(5, 10)) # arbitrary coordinates
@event.coords = marnen.coords
helper.distance_string(@event, marnen).should =~ /\D\d(\.\d+)? miles/
user = User.new
# distance_string(@event, user).should == "" # user.coords is nil -- this spec is not working right now
@event = Event.new do |e| e.coords = Point.from_x_y(0, 2) end
user.coords = Point.from_x_y(0, 1)
helper.distance_string(@event, user).should =~ /\D6(8.7)|9.*miles.*#{h('•')}$/ # 1 degree of latitude
end
it "should generate a sort link for a table header (asc unless desc is specified)" do
@request.stub!(:path_parameters).and_return(:controller => 'events', :action => 'index')
link = helper.sort_link("Date", :date)
link.should be_a_kind_of(String)
link.should match(/\A<a [^>]*href="#{url_for :controller => 'events', :action => 'index', :order => :date, :direction => :asc}".*<\/a>\Z/i)
link.should have_tag("a.sort", "Date")
#link = sort_link("Date", :date, :desc)
#link.should match(/\A<a [^>]*href="#{url_for :controller => 'events', :action => 'index', :order => :date, :direction => :desc}".*<\/a>\Z/i)
end
end
describe EventsHelper, "event_map" do
before(:each) do
User.stub!(:current_user).and_return(User.make)
end
it "should set up a GMap with all the options" do
event = Event.make
# TODO: since this code is now in events/map.js , translate these specs into JavaScript!
=begin
marker = GMarker.new([1.0, 2.0])
gmap_header = "[Stubbed header for #{DOMAIN}]"
GMap.should_receive(:header).with(:host => DOMAIN).at_least(:once).and_return(gmap_header)
GMarker.stub!(:new).and_return(marker)
gmap.should_receive(:center_zoom_init)
gmap.should_receive(:overlay_init).with(marker)
marker.should_receive(:open_info_window).with(EventsHelper::ElementVar.new(helper.info(event)))
gmap.should_receive(:control_init) do |opts|
opts.should be_a_kind_of(Hash)
opts.should have_key(:large_map)
opts[:large_map].should == true
opts.should have_key(:map_type)
opts[:map_type].should == true
end
gmap.should_receive(:to_html).at_least(:once)
=end
gmap_header = "[Stubbed header for #{DOMAIN}]"
GMap.should_receive(:header).with(:host => DOMAIN).at_least(:once).and_return(gmap_header)
gmap = GMap.new(:gmap)
gmap_div = '<div id="gmap">GMap div</div>'
gmap.should_receive(:div).and_return(gmap_div)
GMap.should_receive(:new).and_return(gmap)
info_div = '<div id="info">Event info</div>'
helper.should_receive(:info).with(event).at_least(:once).and_return(info_div)
map = helper.event_map(event, DOMAIN)
{'#gmap' => nil, '#info' => nil, '#lat' => ERB::Util::h(event.coords.lat), '#lng' => ERB::Util::h(event.coords.lng)}.each do |k, v|
map.should have_tag(k, v)
end
assigns[:extra_headers].should_not be_nil
assigns[:extra_headers].should include(gmap_header)
assigns[:extra_headers].should include(javascript_include_tag 'events/map')
end
end
describe EventsHelper, "ical_escape" do
it "should make newlines into '\n'" do
helper.ical_escape("a\na").should == 'a\\na'
end
it "should double backslashes" do
bb = '\\' + '\\'
helper.ical_escape('\\c\\n\\').should == bb + 'c' + bb + 'n' + bb
end
it "should put backslashes before commas and semicolons" do
helper.ical_escape('comma,semicolon;').should == 'comma\\,semicolon\\;'
end
end
describe EventsHelper, "list_names" do
it "should return an empty string when called with nil argument" do
helper.list_names(nil).should == ''
end
end
describe EventsHelper, "markdown_hint" do
it "should return a span of class 'hint' with a link to Markdown in it" do
m = helper.markdown_hint
m.should match(%r{^<span class=(['"])hint\1[^>]*>.*</span>$})
m.should have_tag('a[target="markdown"]', 'Markdown')
end
end
describe EventsHelper, "rss_url" do
it "should return the RSS feed URL for the current user" do
user = User.make
User.current_user = user
helper.rss_url.should == feed_events_url(:fmt => :rss, :key => user.feed_key)
end
it "should return nil if there is no current user" do
User.current_user = false
helper.rss_url.should be_nil
User.current_user = nil
helper.rss_url.should be_nil
end
end