Commit 045fbc74fe3f6e214d89a671f2bbead3a30bac05

Authored by Rodrigo Souto
1 parent 631b96a0

rails3: fix event tests

PS: still failing xss_terminate related tests
Showing 2 changed files with 28 additions and 25 deletions   Show diff stats
app/models/event.rb
1 1 require 'noosfero/translatable_content'
  2 +require 'builder'
2 3  
3 4 class Event < Article
4 5  
  6 + attr_accessible :start_date, :end_date, :link
  7 +
5 8 def self.type_name
6 9 _('Event')
7 10 end
... ... @@ -88,7 +91,7 @@ class Event &lt; Article
88 91 def to_html(options = {})
89 92  
90 93 result = ''
91   - html = Builder::XmlMarkup.new(:target => result)
  94 + html = ::Builder::XmlMarkup.new(:target => result)
92 95  
93 96 html.div(:class => 'event-info' ) {
94 97  
... ...
test/unit/event_test.rb
... ... @@ -15,17 +15,17 @@ class EventTest &lt; ActiveSupport::TestCase
15 15 end
16 16  
17 17 should 'have a body' do
18   - e = Event.new(:body => 'some useful description')
  18 + e = build(Event, :body => 'some useful description')
19 19 assert_equal 'some useful description', e.body
20 20 end
21 21  
22 22 should 'have a link' do
23   - e = Event.new(:link => 'http://some.nice.site/')
  23 + e = build(Event, :link => 'http://some.nice.site/')
24 24 assert_equal 'http://some.nice.site/', e.link
25 25 end
26 26  
27 27 should 'have an address' do
28   - e = Event.new(:address => 'South Noosfero street, 88')
  28 + e = build(Event, :address => 'South Noosfero street, 88')
29 29 assert_equal 'South Noosfero street, 88', e.address
30 30 end
31 31  
... ... @@ -61,7 +61,7 @@ class EventTest &lt; ActiveSupport::TestCase
61 61 end
62 62  
63 63 should 'not allow end date before start date' do
64   - e = Event.new(:start_date => Date.new(2008, 01, 01), :end_date => Date.new(2007,01,01))
  64 + e = build(Event, :start_date => Date.new(2008, 01, 01), :end_date => Date.new(2007,01,01))
65 65 e.valid?
66 66 assert e.errors[:start_date.to_s].present?
67 67  
... ... @@ -72,9 +72,9 @@ class EventTest &lt; ActiveSupport::TestCase
72 72  
73 73 should 'find by range of dates' do
74 74 profile = create_user('testuser').person
75   - e1 = Event.create!(:name => 'e1', :start_date => Date.new(2008,1,1), :profile => profile)
76   - e2 = Event.create!(:name => 'e2', :start_date => Date.new(2008,2,1), :profile => profile)
77   - e3 = Event.create!(:name => 'e3', :start_date => Date.new(2008,3,1), :profile => profile)
  75 + e1 = create(Event, :name => 'e1', :start_date => Date.new(2008,1,1), :profile => profile)
  76 + e2 = create(Event, :name => 'e2', :start_date => Date.new(2008,2,1), :profile => profile)
  77 + e3 = create(Event, :name => 'e3', :start_date => Date.new(2008,3,1), :profile => profile)
78 78  
79 79 found = Event.by_range(Date.new(2008, 1, 1)..Date.new(2008, 2, 28))
80 80 assert_includes found, e1
... ... @@ -84,7 +84,7 @@ class EventTest &lt; ActiveSupport::TestCase
84 84  
85 85 should 'filter events by range' do
86 86 profile = create_user('testuser').person
87   - e1 = Event.create!(:name => 'e1', :start_date => Date.new(2008,1,15), :profile => profile)
  87 + e1 = create(Event, :name => 'e1', :start_date => Date.new(2008,1,15), :profile => profile)
88 88 assert_includes profile.events.by_range(Date.new(2008, 1, 10)..Date.new(2008, 1, 20)), e1
89 89 end
90 90  
... ... @@ -99,19 +99,19 @@ class EventTest &lt; ActiveSupport::TestCase
99 99 end
100 100  
101 101 should 'provide range of dates for event with both dates filled' do
102   - e = Event.new(:start_date => Date.new(2008, 1, 1), :end_date => Date.new(2008, 1, 5))
  102 + e = build(Event, :start_date => Date.new(2008, 1, 1), :end_date => Date.new(2008, 1, 5))
103 103  
104 104 assert_equal (Date.new(2008,1,1)..Date.new(2008,1,5)), e.date_range
105 105 end
106 106  
107 107 should 'provide range of dates for event with only start date' do
108   - e = Event.new(:start_date => Date.new(2008, 1, 1))
  108 + e = build(Event, :start_date => Date.new(2008, 1, 1))
109 109  
110 110 assert_equal (Date.new(2008,1,1)..Date.new(2008,1,1)), e.date_range
111 111 end
112 112  
113 113 should 'provide nice display format' do
114   - e = Event.new(:start_date => Date.new(2008,1,1), :end_date => Date.new(2008,1,1), :link => 'http://www.myevent.org', :body => 'my somewhat short description')
  114 + e = build(Event, :start_date => Date.new(2008,1,1), :end_date => Date.new(2008,1,1), :link => 'http://www.myevent.org', :body => 'my somewhat short description')
115 115  
116 116 assert_tag_in_string e.to_html, :content => Regexp.new("January 1, 2008")
117 117 assert_tag_in_string e.to_html, :content => 'my somewhat short description'
... ... @@ -126,7 +126,7 @@ class EventTest &lt; ActiveSupport::TestCase
126 126 end
127 127  
128 128 should 'add http:// to the link if not already present' do
129   - a = Event.new(:link => 'www.nohttp.net')
  129 + a = build(Event, :link => 'www.nohttp.net')
130 130 assert_equal 'http://www.nohttp.net', a.link
131 131 end
132 132  
... ... @@ -145,14 +145,14 @@ class EventTest &lt; ActiveSupport::TestCase
145 145 end
146 146  
147 147 should 'not escape HTML in body' do
148   - a = Event.new(:body => '<p>a paragraph of text</p>', :link => 'www.gnu.org')
  148 + a = build(Event, :body => '<p>a paragraph of text</p>', :link => 'www.gnu.org')
149 149  
150 150 assert_match '<p>a paragraph of text</p>', a.to_html
151 151 end
152 152  
153 153 should 'filter HTML in body' do
154 154 profile = create_user('testuser').person
155   - e = Event.create!(:profile => profile, :name => 'test', :body => '<p>a paragraph (valid)</p><script type="text/javascript">/* this is invalid */</script>"', :link => 'www.colivre.coop.br', :start_date => Date.today)
  155 + e = create(Event, :profile => profile, :name => 'test', :body => '<p>a paragraph (valid)</p><script type="text/javascript">/* this is invalid */</script>"', :link => 'www.colivre.coop.br', :start_date => Date.today)
156 156  
157 157 assert_tag_in_string e.body, :tag => 'p', :content => 'a paragraph (valid)'
158 158 assert_no_tag_in_string e.body, :tag => 'script'
... ... @@ -167,8 +167,8 @@ class EventTest &lt; ActiveSupport::TestCase
167 167  
168 168 should 'list all events' do
169 169 profile = fast_create(Profile)
170   - event1 = Event.new(:name => 'Ze Birthday', :start_date => Date.today)
171   - event2 = Event.new(:name => 'Mane Birthday', :start_date => Date.today >> 1)
  170 + event1 = build(Event, :name => 'Ze Birthday', :start_date => Date.today)
  171 + event2 = build(Event, :name => 'Mane Birthday', :start_date => Date.today >> 1)
172 172 profile.events << [event1, event2]
173 173 assert_includes profile.events, event1
174 174 assert_includes profile.events, event2
... ... @@ -178,9 +178,9 @@ class EventTest &lt; ActiveSupport::TestCase
178 178 profile = fast_create(Profile)
179 179  
180 180 today = Date.today
181   - yesterday_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.day)
182   - today_event = Event.new(:name => 'Ze Birthday', :start_date => today)
183   - tomorrow_event = Event.new(:name => 'Mane Birthday', :start_date => today + 1.day)
  181 + yesterday_event = build(Event, :name => 'Joao Birthday', :start_date => today - 1.day)
  182 + today_event = build(Event, :name => 'Ze Birthday', :start_date => today)
  183 + tomorrow_event = build(Event, :name => 'Mane Birthday', :start_date => today + 1.day)
184 184  
185 185 profile.events << [yesterday_event, today_event, tomorrow_event]
186 186  
... ... @@ -191,8 +191,8 @@ class EventTest &lt; ActiveSupport::TestCase
191 191 profile = fast_create(Profile)
192 192  
193 193 today = Date.today
194   - event_in_range = Event.new(:name => 'Noosfero Conference', :start_date => today - 2.day, :end_date => today + 2.day)
195   - event_in_day = Event.new(:name => 'Ze Birthday', :start_date => today)
  194 + event_in_range = build(Event, :name => 'Noosfero Conference', :start_date => today - 2.day, :end_date => today + 2.day)
  195 + event_in_day = build(Event, :name => 'Ze Birthday', :start_date => today)
196 196  
197 197 profile.events << [event_in_range, event_in_day]
198 198  
... ... @@ -205,9 +205,9 @@ class EventTest &lt; ActiveSupport::TestCase
205 205 profile = fast_create(Profile)
206 206  
207 207 today = Date.today
208   - event_in_range1 = Event.new(:name => 'Foswiki Conference', :start_date => today - 2.day, :end_date => today + 2.day)
209   - event_in_range2 = Event.new(:name => 'Debian Conference', :start_date => today - 2.day, :end_date => today + 3.day)
210   - event_out_of_range = Event.new(:name => 'Ze Birthday', :start_date => today - 5.day, :end_date => today - 3.day)
  208 + event_in_range1 = build(Event, :name => 'Foswiki Conference', :start_date => today - 2.day, :end_date => today + 2.day)
  209 + event_in_range2 = build(Event, :name => 'Debian Conference', :start_date => today - 2.day, :end_date => today + 3.day)
  210 + event_out_of_range = build(Event, :name => 'Ze Birthday', :start_date => today - 5.day, :end_date => today - 3.day)
211 211  
212 212 profile.events << [event_in_range1, event_in_range2, event_out_of_range]
213 213  
... ...