Commit 5de7fb8b9a5b77de7d8c03f38f6a7436518177cd
Exists in
staging
and in
42 other branches
Merge branch 'rails3' of gitorious.org:noosfero/noosfero into rails3
Showing
17 changed files
with
182 additions
and
138 deletions
Show diff stats
app/models/article.rb
app/models/blog.rb
... | ... | @@ -46,7 +46,9 @@ class Blog < Folder |
46 | 46 | self.external_feed_data = efeed |
47 | 47 | end |
48 | 48 | |
49 | - def validate | |
49 | + validate :prepare_external_feed | |
50 | + | |
51 | + def prepare_external_feed | |
50 | 52 | unless self.external_feed_data.nil? |
51 | 53 | if self.external_feed(true) && self.external_feed.id == self.external_feed_data[:id].to_i |
52 | 54 | self.external_feed.attributes = self.external_feed_data | ... | ... |
app/models/create_enterprise.rb
... | ... | @@ -36,14 +36,18 @@ class CreateEnterprise < Task |
36 | 36 | validates_presence_of :reject_explanation, :if => (lambda { |record| record.status == Task::Status::CANCELLED } ) |
37 | 37 | xss_terminate :only => [ :acronym, :address, :contact_person, :contact_phone, :economic_activity, :legal_form, :management_information, :name ], :on => 'validation' |
38 | 38 | |
39 | - def validate | |
39 | + validate :validator_correct_region | |
40 | + validate :not_used_identifier | |
40 | 41 | |
42 | + def validator_correct_region | |
41 | 43 | if self.region && self.target |
42 | 44 | unless self.region.validators.include?(self.target) || self.target_type == "Environment" |
43 | 45 | self.errors.add(:target, _('%{fn} is not a validator for the chosen region').fix_i18n) |
44 | 46 | end |
45 | 47 | end |
48 | + end | |
46 | 49 | |
50 | + def not_used_identifier | |
47 | 51 | if self.status != Task::Status::CANCELLED && self.identifier && Profile.exists?(:identifier => self.identifier) |
48 | 52 | self.errors.add(:identifier, _('%{fn} is already being as identifier by another enterprise, organization or person.').fix_i18n) |
49 | 53 | end | ... | ... |
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 < 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 | ... | ... |
app/models/external_feed.rb
... | ... | @@ -10,6 +10,8 @@ class ExternalFeed < ActiveRecord::Base |
10 | 10 | { :conditions => ['(fetched_at is NULL) OR (fetched_at < ?)', Time.now - FeedUpdater.update_interval] } |
11 | 11 | } |
12 | 12 | |
13 | + attr_accessible :address, :enabled | |
14 | + | |
13 | 15 | def add_item(title, link, date, content) |
14 | 16 | doc = Hpricot(content) |
15 | 17 | doc.search('*').each do |p| | ... | ... |
app/models/rss_feed.rb
app/models/uploaded_file.rb
... | ... | @@ -6,6 +6,8 @@ require 'short_filename' |
6 | 6 | # of the file itself is kept. (FIXME?) |
7 | 7 | class UploadedFile < Article |
8 | 8 | |
9 | + attr_accessible :uploaded_data | |
10 | + | |
9 | 11 | def self.type_name |
10 | 12 | _('File') |
11 | 13 | end |
... | ... | @@ -31,7 +33,7 @@ class UploadedFile < Article |
31 | 33 | end |
32 | 34 | |
33 | 35 | def thumbnail_path |
34 | - self.image? ? self.full_filename(:display).gsub(Rails.root.join('public'), '') : nil | |
36 | + self.image? ? self.full_filename(:display).to_s.gsub(Rails.root.join('public'), '') : nil | |
35 | 37 | end |
36 | 38 | |
37 | 39 | def display_title | ... | ... |
lib/acts_as_having_posts.rb
test/unit/blog_test.rb
... | ... | @@ -38,14 +38,14 @@ class BlogTest < ActiveSupport::TestCase |
38 | 38 | |
39 | 39 | should 'save feed options' do |
40 | 40 | p = create_user('testuser').person |
41 | - p.articles << Blog.new(:profile => p, :name => 'blog_feed_test') | |
41 | + p.articles << build(Blog, :profile => p, :name => 'blog_feed_test') | |
42 | 42 | p.blog.feed = { :limit => 7 } |
43 | 43 | assert_equal 7, p.blog.feed.limit |
44 | 44 | end |
45 | 45 | |
46 | 46 | should 'save feed options after create blog' do |
47 | 47 | p = create_user('testuser').person |
48 | - p.articles << Blog.new(:profile => p, :name => 'blog_feed_test', :feed => { :limit => 7 }) | |
48 | + p.articles << build(Blog, :profile => p, :name => 'blog_feed_test', :feed => { :limit => 7 }) | |
49 | 49 | assert_equal 7, p.blog.feed.limit |
50 | 50 | end |
51 | 51 | |
... | ... | @@ -56,7 +56,7 @@ class BlogTest < ActiveSupport::TestCase |
56 | 56 | |
57 | 57 | should 'update posts per page setting' do |
58 | 58 | p = create_user('testuser').person |
59 | - p.articles << Blog.new(:profile => p, :name => 'Blog test') | |
59 | + p.articles << build(Blog, :profile => p, :name => 'Blog test') | |
60 | 60 | blog = p.blog |
61 | 61 | blog.posts_per_page = 7 |
62 | 62 | assert blog.save! |
... | ... | @@ -95,7 +95,7 @@ class BlogTest < ActiveSupport::TestCase |
95 | 95 | |
96 | 96 | should 'build external feed after save' do |
97 | 97 | p = create_user('testuser').person |
98 | - blog = Blog.new(:profile => p, :name => 'Blog test') | |
98 | + blog = build(Blog, :profile => p, :name => 'Blog test') | |
99 | 99 | blog.external_feed_builder = { :address => 'feed address' } |
100 | 100 | blog.save! |
101 | 101 | assert blog.external_feed.valid? |
... | ... | @@ -103,9 +103,9 @@ class BlogTest < ActiveSupport::TestCase |
103 | 103 | |
104 | 104 | should 'update external feed' do |
105 | 105 | p = create_user('testuser').person |
106 | - blog = Blog.new(:profile => p, :name => 'Blog test') | |
106 | + blog = build(Blog, :profile => p, :name => 'Blog test') | |
107 | 107 | blog.save |
108 | - e = ExternalFeed.new(:address => 'feed address') | |
108 | + e = build(ExternalFeed, :address => 'feed address') | |
109 | 109 | e.blog = blog |
110 | 110 | e.save |
111 | 111 | blog.reload |
... | ... | @@ -116,14 +116,14 @@ class BlogTest < ActiveSupport::TestCase |
116 | 116 | |
117 | 117 | should 'invalid blog if has invalid external_feed' do |
118 | 118 | p = create_user('testuser').person |
119 | - blog = Blog.new(:profile => p, :name => 'Blog test', :external_feed_builder => {:enabled => true}) | |
119 | + blog = build(Blog, :profile => p, :name => 'Blog test', :external_feed_builder => {:enabled => true}) | |
120 | 120 | blog.save |
121 | 121 | assert ! blog.valid? |
122 | 122 | end |
123 | 123 | |
124 | 124 | should 'remove external feed when removing blog' do |
125 | 125 | p = create_user('testuser').person |
126 | - blog = Blog.create!(:name => 'Blog test', :profile => p, :external_feed_builder => {:enabled => true, :address => "http://bli.org/feed"}) | |
126 | + blog = create(Blog, :name => 'Blog test', :profile => p, :external_feed_builder => {:enabled => true, :address => "http://bli.org/feed"}) | |
127 | 127 | assert blog.external_feed |
128 | 128 | assert_difference ExternalFeed, :count, -1 do |
129 | 129 | blog.destroy |
... | ... | @@ -134,16 +134,17 @@ class BlogTest < ActiveSupport::TestCase |
134 | 134 | p = create_user('testuser').person |
135 | 135 | fast_create(Blog, :name => 'Blog test', :profile_id => p.id) |
136 | 136 | assert_nothing_raised ActiveRecord::RecordInvalid do |
137 | - Blog.create!(:name => 'Another Blog', :profile => p) | |
137 | + create(Blog, :name => 'Another Blog', :profile => p) | |
138 | 138 | end |
139 | 139 | end |
140 | 140 | |
141 | 141 | should 'not update slug from name for existing blog' do |
142 | 142 | p = create_user('testuser').person |
143 | - blog = Blog.create!(:name => 'Blog test', :profile => p) | |
144 | - assert_equal 'blog-test', blog.slug | |
145 | - blog.name = 'Changed name' | |
146 | - assert_not_equal 'changed-name', blog.slug | |
143 | + blog = create(Blog, :profile => p) | |
144 | + new_name = 'Changed name' | |
145 | + assert_not_equal new_name.to_slug, blog.slug | |
146 | + blog.name = new_name | |
147 | + assert_not_equal new_name.to_slug, blog.slug | |
147 | 148 | end |
148 | 149 | |
149 | 150 | should 'display full posts by default' do |
... | ... | @@ -153,7 +154,7 @@ class BlogTest < ActiveSupport::TestCase |
153 | 154 | |
154 | 155 | should 'update visualization_format setting' do |
155 | 156 | p = create_user('testuser').person |
156 | - p.articles << Blog.new(:profile => p, :name => 'Blog test') | |
157 | + p.articles << build(Blog, :profile => p, :name => 'Blog test') | |
157 | 158 | blog = p.blog |
158 | 159 | blog.visualization_format = 'short' |
159 | 160 | assert blog.save! |
... | ... | @@ -161,7 +162,7 @@ class BlogTest < ActiveSupport::TestCase |
161 | 162 | end |
162 | 163 | |
163 | 164 | should 'allow only full and short as visualization_format' do |
164 | - blog = Blog.new(:name => 'blog') | |
165 | + blog = build(Blog, :name => 'blog') | |
165 | 166 | blog.visualization_format = 'wrong_format' |
166 | 167 | blog.valid? |
167 | 168 | assert blog.errors[:visualization_format.to_s].present? |
... | ... | @@ -187,7 +188,7 @@ class BlogTest < ActiveSupport::TestCase |
187 | 188 | |
188 | 189 | should 'update display posts in current language setting' do |
189 | 190 | p = create_user('testuser').person |
190 | - p.articles << Blog.new(:profile => p, :name => 'Blog test') | |
191 | + p.articles << build(Blog, :profile => p, :name => 'Blog test') | |
191 | 192 | blog = p.blog |
192 | 193 | blog.display_posts_in_current_language = false |
193 | 194 | assert blog.save! && blog.reload | ... | ... |
test/unit/create_enterprise_test.rb
... | ... | @@ -232,11 +232,11 @@ class CreateEnterpriseTest < ActiveSupport::TestCase |
232 | 232 | request.stubs(:environment).returns(Environment.default) |
233 | 233 | request.identifier = 'testid' |
234 | 234 | request.valid? |
235 | - assert !request.errors[:identifier.to_s].present? | |
235 | + assert request.errors[:identifier].blank? | |
236 | 236 | |
237 | 237 | Organization.create!(:name => 'test', :identifier => 'testid') |
238 | 238 | request.valid? |
239 | - assert request.errors[:identifier.to_s].present? | |
239 | + assert request.errors[:identifier].present? | |
240 | 240 | end |
241 | 241 | |
242 | 242 | should 'require the same fields as an enterprise does' do |
... | ... | @@ -247,11 +247,11 @@ class CreateEnterpriseTest < ActiveSupport::TestCase |
247 | 247 | |
248 | 248 | environment.stubs(:required_enterprise_fields).returns([]) |
249 | 249 | request.valid? |
250 | - assert_nil request.errors[:contact_person], 'should not require contact_person unless Enterprise requires it' | |
250 | + assert request.errors[:contact_person].blank?, 'should not require contact_person unless Enterprise requires it' | |
251 | 251 | |
252 | 252 | environment.stubs(:required_enterprise_fields).returns(['contact_person']) |
253 | 253 | request.valid? |
254 | - assert_not_nil request.errors[:contact_person], 'should require contact_person when Enterprise requires it' | |
254 | + assert request.errors[:contact_person].present?, 'should require contact_person when Enterprise requires it' | |
255 | 255 | end |
256 | 256 | |
257 | 257 | should 'has permission to validate enterprise' do | ... | ... |
test/unit/event_test.rb
... | ... | @@ -15,17 +15,17 @@ class EventTest < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 < 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 | ... | ... |
test/unit/forum_test.rb
... | ... | @@ -95,9 +95,10 @@ class ForumTest < ActiveSupport::TestCase |
95 | 95 | should 'not update slug from name for existing forum' do |
96 | 96 | p = create_user('testuser').person |
97 | 97 | forum = create(Forum, :name => 'Forum test', :profile_id => p.id, :body => 'Forum') |
98 | - assert_equal 'forum-test', forum.slug | |
99 | - forum.name = 'Changed name' | |
100 | - assert_not_equal 'changed-name', forum.slug | |
98 | + new_name = 'Changed name' | |
99 | + assert_not_equal new_name.to_slug, forum.slug | |
100 | + forum.name = new_name | |
101 | + assert_not_equal new_name.to_slug, forum.slug | |
101 | 102 | end |
102 | 103 | |
103 | 104 | should 'have posts' do | ... | ... |
test/unit/rss_feed_test.rb
... | ... | @@ -29,7 +29,7 @@ class RssFeedTest < ActiveSupport::TestCase |
29 | 29 | a2 = profile.articles.build(:name => 'article 2'); a2.save! |
30 | 30 | a3 = profile.articles.build(:name => 'article 3'); a3.save! |
31 | 31 | |
32 | - feed = RssFeed.new(:name => 'testfeed') | |
32 | + feed = build(RssFeed, :name => 'testfeed') | |
33 | 33 | feed.profile = profile |
34 | 34 | feed.save! |
35 | 35 | |
... | ... | @@ -45,7 +45,7 @@ class RssFeedTest < ActiveSupport::TestCase |
45 | 45 | a2 = profile.articles.build(:name => 'article 2'); a2.save! |
46 | 46 | a3 = profile.articles.build(:name => 'article 3'); a3.save! |
47 | 47 | |
48 | - feed = RssFeed.new(:name => 'testfeed') | |
48 | + feed = build(RssFeed, :name => 'testfeed') | |
49 | 49 | feed.profile = profile |
50 | 50 | feed.save! |
51 | 51 | |
... | ... | @@ -73,7 +73,7 @@ class RssFeedTest < ActiveSupport::TestCase |
73 | 73 | a3_2_1 = a3_2.children.build(:name => 'article 3.2.1', :parent => a3_2, :profile => profile); a3_2_1.save! |
74 | 74 | |
75 | 75 | a3.reload |
76 | - feed = RssFeed.new(:name => 'testfeed') | |
76 | + feed = build(RssFeed, :name => 'testfeed') | |
77 | 77 | feed.parent = a3 |
78 | 78 | feed.profile = profile |
79 | 79 | feed.include = 'parent_and_children' |
... | ... | @@ -91,7 +91,7 @@ class RssFeedTest < ActiveSupport::TestCase |
91 | 91 | |
92 | 92 | should 'list blog posts with more recent first and respecting limit' do |
93 | 93 | profile = create_user('testuser').person |
94 | - blog = Blog.create!(:name => 'blog-test', :profile => profile) | |
94 | + blog = create(Blog, :name => 'blog-test', :profile => profile) | |
95 | 95 | posts = [] |
96 | 96 | 6.times do |i| |
97 | 97 | posts << fast_create(TextArticle, :name => "post #{i}", :profile_id => profile.id, :parent_id => blog.id) |
... | ... | @@ -105,7 +105,7 @@ class RssFeedTest < ActiveSupport::TestCase |
105 | 105 | |
106 | 106 | should 'list only published posts from blog' do |
107 | 107 | profile = create_user('testuser').person |
108 | - blog = Blog.create!(:name => 'blog-test', :profile => profile) | |
108 | + blog = create(Blog, :name => 'blog-test', :profile => profile) | |
109 | 109 | posts = [] |
110 | 110 | 5.times do |i| |
111 | 111 | posts << fast_create(TextArticle, :name => "post #{i}", :profile_id => profile.id, :parent_id => blog.id) |
... | ... | @@ -119,17 +119,17 @@ class RssFeedTest < ActiveSupport::TestCase |
119 | 119 | |
120 | 120 | should 'provide link to profile' do |
121 | 121 | profile = create_user('testuser').person |
122 | - feed = RssFeed.new(:name => 'testfeed') | |
122 | + feed = build(RssFeed, :name => 'testfeed') | |
123 | 123 | feed.profile = profile |
124 | 124 | feed.save! |
125 | 125 | |
126 | - assert_match "<link>http://#{profile.environment.default_hostname}/testuser</link>", feed.data | |
126 | + assert_match "<link>http://#{profile.environment.default_hostname}/testuser/homepage</link>", feed.data | |
127 | 127 | end |
128 | 128 | |
129 | 129 | should 'provide link to each article' do |
130 | 130 | profile = create_user('testuser').person |
131 | 131 | art = profile.articles.build(:name => 'myarticle'); art.save! |
132 | - feed = RssFeed.new(:name => 'testfeed') | |
132 | + feed = build(RssFeed, :name => 'testfeed') | |
133 | 133 | feed.profile = profile |
134 | 134 | feed.save! |
135 | 135 | |
... | ... | @@ -144,7 +144,7 @@ class RssFeedTest < ActiveSupport::TestCase |
144 | 144 | a2 = profile.articles.build(:name => 'article 2'); a2.save! |
145 | 145 | a3 = profile.articles.build(:name => 'article 3'); a3.save! |
146 | 146 | |
147 | - feed = RssFeed.new(:name => 'testfeed') | |
147 | + feed = build(RssFeed, :name => 'testfeed') | |
148 | 148 | feed.profile = profile |
149 | 149 | feed.save! |
150 | 150 | |
... | ... | @@ -195,13 +195,13 @@ class RssFeedTest < ActiveSupport::TestCase |
195 | 195 | |
196 | 196 | should 'advertise is false before create' do |
197 | 197 | profile = create_user('testuser').person |
198 | - feed = RssFeed.create!(:name => 'testfeed', :profile => profile) | |
198 | + feed = create(RssFeed, :name => 'testfeed', :profile => profile) | |
199 | 199 | assert !feed.advertise? |
200 | 200 | end |
201 | 201 | |
202 | 202 | should 'can display hits' do |
203 | 203 | p = create_user('testuser').person |
204 | - a = RssFeed.create!(:name => 'Test article', :profile => p) | |
204 | + a = create(RssFeed, :name => 'Test article', :profile => p) | |
205 | 205 | assert_equal false, a.can_display_hits? |
206 | 206 | end |
207 | 207 | |
... | ... | @@ -209,14 +209,15 @@ class RssFeedTest < ActiveSupport::TestCase |
209 | 209 | article = fast_create(TextileArticle, :body => 'This is the content of the Sample Article.', :profile_id => fast_create(Person).id) |
210 | 210 | profile = fast_create(Profile) |
211 | 211 | blog = fast_create(Blog, :profile_id => profile.id) |
212 | - a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => fast_create(Person)) | |
212 | + a = create(ApproveArticle, :name => 'test name', :article => article, :target => profile, :requestor => fast_create(Person)) | |
213 | + a.requestor.stubs(:notification_emails).returns(['random@example.org']) | |
213 | 214 | a.finish |
214 | 215 | |
215 | 216 | published_article = article.class.last |
216 | 217 | published_article.parent = blog |
217 | 218 | published_article.save |
218 | 219 | |
219 | - feed = RssFeed.new(:parent => blog, :profile => profile) | |
220 | + feed = build(RssFeed, :parent => blog, :profile => profile) | |
220 | 221 | |
221 | 222 | assert_match "This is the content of the Sample Article", feed.data |
222 | 223 | end |
... | ... | @@ -229,7 +230,7 @@ class RssFeedTest < ActiveSupport::TestCase |
229 | 230 | a2 = profile.articles.build(:name => 'article 2'); a2.save! |
230 | 231 | a3 = profile.articles.build(:name => 'article 3'); a3.save! |
231 | 232 | |
232 | - feed = RssFeed.new(:name => 'testfeed') | |
233 | + feed = build(RssFeed, :name => 'testfeed') | |
233 | 234 | feed.profile = profile |
234 | 235 | feed.save! |
235 | 236 | |
... | ... | @@ -245,7 +246,7 @@ class RssFeedTest < ActiveSupport::TestCase |
245 | 246 | |
246 | 247 | should 'include posts from all languages' do |
247 | 248 | profile = create_user('testuser').person |
248 | - blog = Blog.create!(:name => 'blog-test', :profile => profile, :language => nil) | |
249 | + blog = create(Blog, :name => 'blog-test', :profile => profile, :language => nil) | |
249 | 250 | blog.posts << en_post = fast_create(TextArticle, :name => "English", :profile_id => profile.id, :parent_id => blog.id, :published => true, :language => 'en') |
250 | 251 | blog.posts << es_post = fast_create(TextArticle, :name => "Spanish", :profile_id => profile.id, :parent_id => blog.id, :published => true, :language => 'es') |
251 | 252 | |
... | ... | @@ -255,7 +256,7 @@ class RssFeedTest < ActiveSupport::TestCase |
255 | 256 | |
256 | 257 | should 'include only posts from some language' do |
257 | 258 | profile = create_user('testuser').person |
258 | - blog = Blog.create!(:name => 'blog-test', :profile => profile) | |
259 | + blog = create(Blog, :name => 'blog-test', :profile => profile) | |
259 | 260 | blog.feed.update_attributes! :language => 'es' |
260 | 261 | blog.posts << en_post = fast_create(TextArticle, :name => "English", :profile_id => profile.id, :parent_id => blog.id, :published => true, :language => 'en') |
261 | 262 | blog.posts << es_post = fast_create(TextArticle, :name => "Spanish", :profile_id => profile.id, :parent_id => blog.id, :published => true, :language => 'es') | ... | ... |
test/unit/scrap_test.rb
... | ... | @@ -215,7 +215,7 @@ class ScrapTest < ActiveSupport::TestCase |
215 | 215 | s = fast_create(Scrap, :updated_at => DateTime.parse('2010-01-01')) |
216 | 216 | assert_equal DateTime.parse('2010-01-01'), s.updated_at.strftime('%Y-%m-%d') |
217 | 217 | DateTime.stubs(:now).returns(DateTime.parse('2010-09-07')) |
218 | - s1 = Scrap.create(defaults_for_scrap(:scrap_id => s.id)) | |
218 | + s1 = create(Scrap, defaults_for_scrap(:scrap_id => s.id)) | |
219 | 219 | s.reload |
220 | 220 | assert_not_equal DateTime.parse('2010-01-01'), s.updated_at.strftime('%Y-%m-%d') |
221 | 221 | end |
... | ... | @@ -230,20 +230,20 @@ class ScrapTest < ActiveSupport::TestCase |
230 | 230 | |
231 | 231 | should 'strip all html tags' do |
232 | 232 | s, r = fast_create(Person), fast_create(Person) |
233 | - s = Scrap.new :sender => s, :receiver => r, :content => "<p>Test <b>Rails</b></p>" | |
233 | + s = build Scrap, :sender => s, :receiver => r, :content => "<p>Test <b>Rails</b></p>" | |
234 | 234 | assert_equal "Test Rails", s.strip_all_html_tags |
235 | 235 | end |
236 | 236 | |
237 | 237 | should 'strip html before save' do |
238 | 238 | s, r = fast_create(Person), fast_create(Person) |
239 | - s = Scrap.new :sender => s, :receiver => r, :content => "<p>Test <b>Rails</b></p>" | |
239 | + s = build Scrap, :sender => s, :receiver => r, :content => "<p>Test <b>Rails</b></p>" | |
240 | 240 | s.save! |
241 | 241 | assert_equal "Test Rails", s.reload.content |
242 | 242 | end |
243 | 243 | |
244 | 244 | should 'strip html before validate' do |
245 | 245 | s, r = fast_create(Person), fast_create(Person) |
246 | - s = Scrap.new :sender => s, :receiver => r, :content => "<p><b></b></p>" | |
246 | + s = build Scrap, :sender => s, :receiver => r, :content => "<p><b></b></p>" | |
247 | 247 | assert !s.valid? |
248 | 248 | s.content = "<p>Test</p>" |
249 | 249 | assert s.valid? |
... | ... | @@ -260,15 +260,15 @@ class ScrapTest < ActiveSupport::TestCase |
260 | 260 | |
261 | 261 | should 'scrap wall url be the root scrap receiver url if it is a reply' do |
262 | 262 | p1, p2 = fast_create(Person), fast_create(Person) |
263 | - r = Scrap.create! :sender => p1, :receiver => p2, :content => "Hello!" | |
264 | - s = Scrap.new :sender => p2, :receiver => p1, :content => "Hi!" | |
263 | + r = create Scrap, :sender => p1, :receiver => p2, :content => "Hello!" | |
264 | + s = build Scrap, :sender => p2, :receiver => p1, :content => "Hi!" | |
265 | 265 | r.replies << s; s.reload |
266 | 266 | assert_equal s.scrap_wall_url, s.root.receiver.wall_url |
267 | 267 | end |
268 | 268 | |
269 | 269 | should 'scrap wall url be the scrap receiver url if it is not a reply' do |
270 | 270 | p1, p2 = fast_create(Person), fast_create(Person) |
271 | - s = Scrap.create! :sender => p1, :receiver => p2, :content => "Hello!" | |
271 | + s = create Scrap, :sender => p1, :receiver => p2, :content => "Hello!" | |
272 | 272 | assert_equal s.scrap_wall_url, s.receiver.wall_url |
273 | 273 | end |
274 | 274 | ... | ... |
test/unit/tiny_mce_article_test.rb
... | ... | @@ -23,52 +23,52 @@ class TinyMceArticleTest < ActiveSupport::TestCase |
23 | 23 | end |
24 | 24 | |
25 | 25 | should 'not sanitize target attribute' do |
26 | - article = TinyMceArticle.create!(:name => 'open link in new window', :body => "open <a href='www.invalid.com' target='_blank'>link</a> in new window", :profile => profile) | |
26 | + article = create(TinyMceArticle, :name => 'open link in new window', :body => "open <a href='www.invalid.com' target='_blank'>link</a> in new window", :profile => profile) | |
27 | 27 | assert_tag_in_string article.body, :tag => 'a', :attributes => {:target => '_blank'} |
28 | 28 | end |
29 | 29 | |
30 | 30 | should 'not translate & to amp; over times' do |
31 | - article = TinyMceArticle.create!(:name => 'link', :body => "<a href='www.invalid.com?param1=value¶m2=value'>link</a>", :profile => profile) | |
31 | + article = create(TinyMceArticle, :name => 'link', :body => "<a href='www.invalid.com?param1=value¶m2=value'>link</a>", :profile => profile) | |
32 | 32 | assert article.save |
33 | 33 | assert_no_match(/&amp;/, article.body) |
34 | 34 | assert_match(/&/, article.body) |
35 | 35 | end |
36 | 36 | |
37 | 37 | should 'not escape comments from tiny mce article body' do |
38 | - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "the <!-- comment --> article ...") | |
38 | + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "the <!-- comment --> article ...") | |
39 | 39 | assert_equal "the <!-- comment --> article ...", article.body |
40 | 40 | end |
41 | 41 | |
42 | 42 | should 'convert entities characters to UTF-8 instead of ISO-8859-1' do |
43 | - article = TinyMceArticle.create!(:profile => profile, :name => 'teste ' + Time.now.to_s, :body => '<a title="informática">link</a>') | |
43 | + article = create(TinyMceArticle, :profile => profile, :name => 'teste ' + Time.now.to_s, :body => '<a title="informática">link</a>') | |
44 | 44 | assert(article.body.is_utf8?, "%s expected to be valid UTF-8 content" % article.body.inspect) |
45 | 45 | end |
46 | 46 | |
47 | 47 | should 'fix tinymce mess with itheora comments for IE from tiny mce article body' do |
48 | - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "the <!--–-[if IE]--> just for ie... <!--[endif]-->") | |
49 | - assert_equal "the <!–-[if IE]> just for ie... <![endif]-–>", article.body | |
48 | + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "the <!--–-[if IE]--> just for ie... <!--[endif]-->") | |
49 | + assert_equal "the <!–-[if IE]> just for ie... <![endif]-–>", article.body.html_safe | |
50 | 50 | end |
51 | 51 | |
52 | 52 | should 'remove iframe if it is not from a trusted site' do |
53 | - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe src='http://anything/videos.ogg'></iframe>") | |
53 | + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe src='http://anything/videos.ogg'></iframe>") | |
54 | 54 | assert_equal "", article.body |
55 | 55 | end |
56 | 56 | |
57 | 57 | should 'not mess with <iframe and </iframe if it is from itheora by default' do |
58 | 58 | assert_includes Environment.default.trusted_sites_for_iframe, 'itheora.org' |
59 | - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe src='http://itheora.org/demo/index.php?v=example.ogv'></iframe>") | |
59 | + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe src='http://itheora.org/demo/index.php?v=example.ogv'></iframe>") | |
60 | 60 | assert_tag_in_string article.body, :tag => 'iframe', :attributes => { :src => "http://itheora.org/demo/index.php?v=example.ogv"} |
61 | 61 | end |
62 | 62 | |
63 | 63 | should 'allow iframe if it is from stream.softwarelivre.org by default' do |
64 | 64 | assert_includes Environment.default.trusted_sites_for_iframe, 'stream.softwarelivre.org' |
65 | - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe src='http://stream.softwarelivre.org/fisl10/sites/default/files/videos.ogg'></iframe>") | |
65 | + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe src='http://stream.softwarelivre.org/fisl10/sites/default/files/videos.ogg'></iframe>") | |
66 | 66 | assert_tag_in_string article.body, :tag => 'iframe', :attributes => { :src => "http://stream.softwarelivre.org/fisl10/sites/default/files/videos.ogg"} |
67 | 67 | end |
68 | 68 | |
69 | 69 | should 'allow iframe if it is from tv.softwarelivre.org by default' do |
70 | 70 | assert_includes Environment.default.trusted_sites_for_iframe, 'tv.softwarelivre.org' |
71 | - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe id='player-base' src='http://tv.softwarelivre.org/embed/1170' width='482' height='406' align='right' frameborder='0' scrolling='no'></iframe>") | |
71 | + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe id='player-base' src='http://tv.softwarelivre.org/embed/1170' width='482' height='406' align='right' frameborder='0' scrolling='no'></iframe>") | |
72 | 72 | assert_tag_in_string article.body, :tag => 'iframe', :attributes => { :src => "http://tv.softwarelivre.org/embed/1170", :width => "482", :height => "406", :align => "right", :frameborder => "0", :scrolling => "no"} |
73 | 73 | end |
74 | 74 | |
... | ... | @@ -77,12 +77,12 @@ class TinyMceArticleTest < ActiveSupport::TestCase |
77 | 77 | env.trusted_sites_for_iframe = ['avideosite.com'] |
78 | 78 | env.save |
79 | 79 | assert_includes Environment.default.trusted_sites_for_iframe, 'avideosite.com' |
80 | - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe src='http://avideosite.com/videos.ogg'></iframe>") | |
80 | + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe src='http://avideosite.com/videos.ogg'></iframe>") | |
81 | 81 | assert_tag_in_string article.body, :tag => 'iframe', :attributes => { :src => "http://avideosite.com/videos.ogg"} |
82 | 82 | end |
83 | 83 | |
84 | 84 | should 'remove only the iframe from untrusted site' do |
85 | - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe src='http://stream.softwarelivre.org/videos.ogg'></iframe><iframe src='http://untrusted_site.com/videos.ogg'></iframe>") | |
85 | + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe src='http://stream.softwarelivre.org/videos.ogg'></iframe><iframe src='http://untrusted_site.com/videos.ogg'></iframe>") | |
86 | 86 | assert_tag_in_string article.body, :tag => 'iframe', :attributes => { :src => "http://stream.softwarelivre.org/videos.ogg"} |
87 | 87 | assert_no_tag_in_string article.body, :tag => 'iframe', :attributes => { :src => "http://untrusted_site.com/videos.ogg"} |
88 | 88 | end |
... | ... | @@ -90,13 +90,13 @@ class TinyMceArticleTest < ActiveSupport::TestCase |
90 | 90 | should 'remove iframe if it has 2 or more src' do |
91 | 91 | assert_includes Environment.default.trusted_sites_for_iframe, 'itheora.org' |
92 | 92 | |
93 | - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe src='http://itheora.org/videos.ogg' src='http://untrusted_site.com/videos.ogg'></iframe>") | |
93 | + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe src='http://itheora.org/videos.ogg' src='http://untrusted_site.com/videos.ogg'></iframe>") | |
94 | 94 | assert_equal '', article.body |
95 | 95 | end |
96 | 96 | |
97 | 97 | #TinymMCE convert config={"key":(.*)} in config={"key":(.*)} |
98 | 98 | should 'not replace " with &quot; when adding an Archive.org video' do |
99 | - article = TinyMceArticle.create!(:profile => profile, :name => 'article', :abstract => 'abstract', :body => "<embed flashvars='config={"key":"\#$b6eb72a0f2f1e29f3d4"}'> </embed>") | |
99 | + article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "<embed flashvars='config={"key":"\#$b6eb72a0f2f1e29f3d4"}'> </embed>") | |
100 | 100 | assert_equal "<embed flashvars=\"config={"key":"\#$b6eb72a0f2f1e29f3d4"}\"> </embed>", article.body |
101 | 101 | end |
102 | 102 | |
... | ... | @@ -109,12 +109,12 @@ class TinyMceArticleTest < ActiveSupport::TestCase |
109 | 109 | end |
110 | 110 | |
111 | 111 | should 'not allow XSS on name' do |
112 | - article = TinyMceArticle.create!(:name => 'title with <script>alert("xss")</script>', :profile => profile) | |
112 | + article = create(TinyMceArticle, :name => 'title with <script>alert("xss")</script>', :profile => profile) | |
113 | 113 | assert_no_match /script/, article.name |
114 | 114 | end |
115 | 115 | |
116 | 116 | should 'not allow XSS on abstract' do |
117 | - article = TinyMceArticle.create!(:name => "test 123", :abstract => 'abstract with <script>alert("xss")</script>', :profile => profile) | |
117 | + article = create(TinyMceArticle, :name => "test 123", :abstract => 'abstract with <script>alert("xss")</script>', :profile => profile) | |
118 | 118 | assert_no_match /script/, article.abstract |
119 | 119 | end |
120 | 120 | |
... | ... | @@ -125,17 +125,17 @@ class TinyMceArticleTest < ActiveSupport::TestCase |
125 | 125 | |
126 | 126 | should 'notify activity on create' do |
127 | 127 | ActionTracker::Record.delete_all |
128 | - TinyMceArticle.create! :name => 'test', :profile_id => fast_create(Profile).id, :published => true | |
128 | + create TinyMceArticle, :name => 'test', :profile_id => fast_create(Profile).id, :published => true | |
129 | 129 | assert_equal 1, ActionTracker::Record.count |
130 | 130 | end |
131 | 131 | |
132 | 132 | should 'not group trackers activity of article\'s creation' do |
133 | 133 | ActionTracker::Record.delete_all |
134 | 134 | profile = fast_create(Profile) |
135 | - TinyMceArticle.create! :name => 'bar', :profile_id => profile.id, :published => true | |
136 | - TinyMceArticle.create! :name => 'another bar', :profile_id => profile.id, :published => true | |
135 | + create TinyMceArticle, :name => 'bar', :profile_id => profile.id, :published => true | |
136 | + create TinyMceArticle, :name => 'another bar', :profile_id => profile.id, :published => true | |
137 | 137 | assert_equal 2, ActionTracker::Record.count |
138 | - TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | |
138 | + create TinyMceArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | |
139 | 139 | assert_equal 3, ActionTracker::Record.count |
140 | 140 | end |
141 | 141 | |
... | ... | @@ -154,8 +154,8 @@ class TinyMceArticleTest < ActiveSupport::TestCase |
154 | 154 | |
155 | 155 | should 'not create trackers activity when updating articles' do |
156 | 156 | ActionTracker::Record.delete_all |
157 | - a1 = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | |
158 | - a2 = TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | |
157 | + a1 = create TinyMceArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | |
158 | + a2 = create TinyMceArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | |
159 | 159 | assert_no_difference ActionTracker::Record, :count do |
160 | 160 | a1.name = 'foo';a1.save! |
161 | 161 | a2.name = 'another foo';a2.save! |
... | ... | @@ -164,8 +164,8 @@ class TinyMceArticleTest < ActiveSupport::TestCase |
164 | 164 | |
165 | 165 | should 'remove activity when an article is destroyed' do |
166 | 166 | ActionTracker::Record.delete_all |
167 | - a1 = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | |
168 | - a2 = TinyMceArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | |
167 | + a1 = create TinyMceArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | |
168 | + a2 = create TinyMceArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true | |
169 | 169 | assert_difference ActionTracker::Record, :count, -2 do |
170 | 170 | a1.destroy |
171 | 171 | a2.destroy |
... | ... | @@ -178,20 +178,20 @@ end |
178 | 178 | p1 = Person.first |
179 | 179 | community.add_member(p1) |
180 | 180 | assert p1.is_member_of?(community) |
181 | - article = TinyMceArticle.create! :name => 'test', :profile_id => community.id | |
181 | + article = create TinyMceArticle, :name => 'test', :profile_id => community.id | |
182 | 182 | assert_equal article, ActionTracker::Record.last.target |
183 | 183 | end |
184 | 184 | |
185 | 185 | should "the tracker action target be defined as the article on articles'creation in profile" do |
186 | 186 | ActionTracker::Record.delete_all |
187 | 187 | person = Person.first |
188 | - article = TinyMceArticle.create! :name => 'test', :profile_id => person.id | |
188 | + article = create TinyMceArticle, :name => 'test', :profile_id => person.id | |
189 | 189 | assert_equal article, ActionTracker::Record.last.target |
190 | 190 | end |
191 | 191 | |
192 | 192 | should 'not notify activity if the article is not advertise' do |
193 | 193 | ActionTracker::Record.delete_all |
194 | - a = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true, :advertise => false | |
194 | + a = create TinyMceArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true, :advertise => false | |
195 | 195 | assert_equal true, a.published? |
196 | 196 | assert_equal true, a.notifiable? |
197 | 197 | assert_equal false, a.image? |
... | ... | @@ -204,7 +204,7 @@ end |
204 | 204 | end |
205 | 205 | |
206 | 206 | should "the common trackable conditions return the correct value" do |
207 | - a = TinyMceArticle.new(:profile => profile) | |
207 | + a = build(TinyMceArticle, :profile => profile) | |
208 | 208 | a.published = a.advertise = true |
209 | 209 | assert_equal true, a.published? |
210 | 210 | assert_equal true, a.notifiable? | ... | ... |
test/unit/uploaded_file_test.rb
... | ... | @@ -50,35 +50,35 @@ class UploadedFileTest < ActiveSupport::TestCase |
50 | 50 | end |
51 | 51 | |
52 | 52 | should 'properly save images' do |
53 | - file = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
53 | + file = build(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
54 | 54 | file.profile = profile |
55 | 55 | assert file.save |
56 | 56 | assert file.is_image |
57 | 57 | end |
58 | 58 | |
59 | 59 | should 'has attachment_fu validation options' do |
60 | - file = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
60 | + file = build(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
61 | 61 | assert_respond_to file, :attachment_validation_options |
62 | 62 | end |
63 | 63 | |
64 | 64 | should 'has attachment_fu validation option for size' do |
65 | - file = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
65 | + file = build(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
66 | 66 | assert_includes file.attachment_validation_options, :size |
67 | 67 | end |
68 | 68 | |
69 | 69 | should 'can display hits' do |
70 | - file = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
70 | + file = build(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
71 | 71 | assert_equal false, file.can_display_hits? |
72 | 72 | end |
73 | 73 | |
74 | 74 | should 'not upload files bigger than max_size' do |
75 | - f = UploadedFile.new(:profile => @profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
75 | + f = build(UploadedFile, :profile => @profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
76 | 76 | f.expects(:size).returns(UploadedFile.attachment_options[:max_size] + 1024) |
77 | 77 | assert !f.valid? |
78 | 78 | end |
79 | 79 | |
80 | 80 | should 'upload files smaller than max_size' do |
81 | - f = UploadedFile.new(:profile => @profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
81 | + f = build(UploadedFile, :profile => @profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
82 | 82 | f.expects(:size).returns(UploadedFile.attachment_options[:max_size] - 1024) |
83 | 83 | assert f.valid? |
84 | 84 | end |
... | ... | @@ -86,16 +86,18 @@ class UploadedFileTest < ActiveSupport::TestCase |
86 | 86 | should 'create icon when created in folder' do |
87 | 87 | p = create_user('test_user').person |
88 | 88 | f = fast_create(Folder, :name => 'test_folder', :profile_id => p.id) |
89 | - file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent_id => f.id, :profile => p) | |
89 | + file = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent_id => f.id, :profile => p) | |
90 | 90 | |
91 | 91 | process_delayed_job_queue |
92 | - assert File.exists?(UploadedFile.find(file.id).public_filename(:icon)) | |
92 | + | |
93 | + file.reload | |
94 | + assert File.exists?(file.public_filename(:icon)) | |
93 | 95 | file.destroy |
94 | 96 | end |
95 | 97 | |
96 | 98 | should 'create icon when not created in folder' do |
97 | 99 | p = create_user('test_user').person |
98 | - file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => p) | |
100 | + file = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => p) | |
99 | 101 | |
100 | 102 | process_delayed_job_queue |
101 | 103 | assert File.exists?(UploadedFile.find(file.id).public_filename(:icon)) |
... | ... | @@ -103,7 +105,7 @@ class UploadedFileTest < ActiveSupport::TestCase |
103 | 105 | end |
104 | 106 | |
105 | 107 | should 'match max_size in validates message of size field' do |
106 | - up = UploadedFile.new(:filename => 'fake_filename.png') | |
108 | + up = build(UploadedFile, :filename => 'fake_filename.png') | |
107 | 109 | up.valid? |
108 | 110 | |
109 | 111 | assert_match /#{UploadedFile.max_size.to_humanreadable}/, up.errors[:size] |
... | ... | @@ -111,7 +113,7 @@ class UploadedFileTest < ActiveSupport::TestCase |
111 | 113 | |
112 | 114 | should 'display link to download of non-image files' do |
113 | 115 | p = create_user('test_user').person |
114 | - file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => p) | |
116 | + file = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => p) | |
115 | 117 | |
116 | 118 | stubs(:content_tag).returns('link') |
117 | 119 | expects(:link_to).with(file.name, file.url, :class => file.css_class_name) |
... | ... | @@ -120,7 +122,7 @@ class UploadedFileTest < ActiveSupport::TestCase |
120 | 122 | end |
121 | 123 | |
122 | 124 | should 'have title' do |
123 | - assert_equal 'my title', UploadedFile.new(:title => 'my title').title | |
125 | + assert_equal 'my title', build(UploadedFile, :title => 'my title').title | |
124 | 126 | end |
125 | 127 | |
126 | 128 | should 'limit title to 140 characters' do |
... | ... | @@ -135,7 +137,7 @@ class UploadedFileTest < ActiveSupport::TestCase |
135 | 137 | end |
136 | 138 | |
137 | 139 | should 'always provide a display title' do |
138 | - upload = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | |
140 | + upload = build(UploadedFile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | |
139 | 141 | assert_equal 'test.txt', upload.display_title |
140 | 142 | upload.title = 'My text file' |
141 | 143 | assert_equal 'My text file', upload.display_title |
... | ... | @@ -151,13 +153,13 @@ class UploadedFileTest < ActiveSupport::TestCase |
151 | 153 | end |
152 | 154 | |
153 | 155 | should 'use name as title by default but cut down the title' do |
154 | - upload = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/AGENDA_CULTURA_-_FESTA_DE_VAQUEIROS_PONTO_DE_SERRA_PRETA_BAIXA.txt')) | |
156 | + upload = build(UploadedFile, :uploaded_data => fixture_file_upload('/files/AGENDA_CULTURA_-_FESTA_DE_VAQUEIROS_PONTO_DE_SERRA_PRETA_BAIXA.txt')) | |
155 | 157 | upload.valid? |
156 | 158 | assert_nil upload.errors[:title] |
157 | 159 | end |
158 | 160 | |
159 | 161 | should 'create thumbnails after processing jobs' do |
160 | - file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => profile) | |
162 | + file = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => profile) | |
161 | 163 | |
162 | 164 | process_delayed_job_queue |
163 | 165 | |
... | ... | @@ -168,7 +170,7 @@ class UploadedFileTest < ActiveSupport::TestCase |
168 | 170 | end |
169 | 171 | |
170 | 172 | should 'set thumbnails_processed to true after creating thumbnails' do |
171 | - file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => profile) | |
173 | + file = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => profile) | |
172 | 174 | |
173 | 175 | process_delayed_job_queue |
174 | 176 | |
... | ... | @@ -198,7 +200,7 @@ class UploadedFileTest < ActiveSupport::TestCase |
198 | 200 | end |
199 | 201 | |
200 | 202 | should 'return image thumbnail if thumbnails were processed' do |
201 | - file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => profile) | |
203 | + file = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => profile) | |
202 | 204 | process_delayed_job_queue |
203 | 205 | |
204 | 206 | assert_match(/rails_thumb.png/, UploadedFile.find(file.id).public_filename(:thumb)) |
... | ... | @@ -214,7 +216,7 @@ class UploadedFileTest < ActiveSupport::TestCase |
214 | 216 | end |
215 | 217 | |
216 | 218 | should 'store width and height after processing' do |
217 | - file = UploadedFile.create!(:profile => @profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
219 | + file = create(UploadedFile, :profile => @profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | |
218 | 220 | file.create_thumbnails |
219 | 221 | |
220 | 222 | file = UploadedFile.find(file.id) |
... | ... | @@ -241,7 +243,7 @@ class UploadedFileTest < ActiveSupport::TestCase |
241 | 243 | |
242 | 244 | should 'track action when a published image is uploaded in a gallery' do |
243 | 245 | p = fast_create(Gallery, :profile_id => @profile.id) |
244 | - f = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile) | |
246 | + f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile) | |
245 | 247 | ta = ActionTracker::Record.last(:conditions => { :verb => "upload_image" }) |
246 | 248 | assert_kind_of String, ta.get_thumbnail_path[0] |
247 | 249 | assert_equal [f.reload.view_url], ta.get_view_url |
... | ... | @@ -252,26 +254,26 @@ class UploadedFileTest < ActiveSupport::TestCase |
252 | 254 | should 'not track action when is not image' do |
253 | 255 | ActionTracker::Record.delete_all |
254 | 256 | p = fast_create(Gallery, :profile_id => @profile.id) |
255 | - f = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :parent => p, :profile => @profile) | |
257 | + f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :parent => p, :profile => @profile) | |
256 | 258 | assert_nil ActionTracker::Record.last(:conditions => { :verb => "upload_image" }) |
257 | 259 | end |
258 | 260 | |
259 | 261 | should 'not track action when has no parent' do |
260 | - f = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => nil, :profile => @profile) | |
262 | + f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => nil, :profile => @profile) | |
261 | 263 | assert_nil ActionTracker::Record.last(:conditions => { :verb => "upload_image" }) |
262 | 264 | end |
263 | 265 | |
264 | 266 | should 'not track action when is not published' do |
265 | 267 | ActionTracker::Record.delete_all |
266 | 268 | p = fast_create(Gallery, :profile_id => @profile.id) |
267 | - f = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile, :published => false) | |
269 | + f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile, :published => false) | |
268 | 270 | assert_nil ActionTracker::Record.last(:conditions => { :verb => "upload_image" }) |
269 | 271 | end |
270 | 272 | |
271 | 273 | should 'not track action when parent is not gallery' do |
272 | 274 | ActionTracker::Record.delete_all |
273 | 275 | p = fast_create(Folder, :profile_id => @profile.id) |
274 | - f = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile) | |
276 | + f = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => p, :profile => @profile) | |
275 | 277 | assert_nil ActionTracker::Record.last(:conditions => { :verb => "upload_image" }) |
276 | 278 | end |
277 | 279 | |
... | ... | @@ -295,11 +297,11 @@ class UploadedFileTest < ActiveSupport::TestCase |
295 | 297 | |
296 | 298 | should 'upload to a folder with same name as the schema if database is postgresql' do |
297 | 299 | uses_postgresql 'image_schema_one' |
298 | - file1 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => @profile) | |
300 | + file1 = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => @profile) | |
299 | 301 | process_delayed_job_queue |
300 | 302 | assert_match(/image_schema_one\/\d{4}\/\d{4}\/rails.png/, UploadedFile.find(file1.id).public_filename) |
301 | 303 | uses_postgresql 'image_schema_two' |
302 | - file2 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => @profile) | |
304 | + file2 = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => @profile) | |
303 | 305 | assert_match(/image_schema_two\/\d{4}\/\d{4}\/test.txt/, UploadedFile.find(file2.id).public_filename) |
304 | 306 | file1.destroy |
305 | 307 | file2.destroy |
... | ... | @@ -307,13 +309,13 @@ class UploadedFileTest < ActiveSupport::TestCase |
307 | 309 | end |
308 | 310 | |
309 | 311 | should 'return extension' do |
310 | - file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => @profile) | |
312 | + file = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => @profile) | |
311 | 313 | assert_equal 'png', file.extension |
312 | 314 | end |
313 | 315 | |
314 | 316 | should 'upload to path prefix folder if database is not postgresql' do |
315 | 317 | uses_sqlite |
316 | - file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => @profile) | |
318 | + file = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => @profile) | |
317 | 319 | assert_match(/\/\d{4}\/\d{4}\/test.txt/, UploadedFile.find(file.id).public_filename) |
318 | 320 | assert_no_match(/test_schema\/\d{4}\/\d{4}\/test.txt/, UploadedFile.find(file.id).public_filename) |
319 | 321 | file.destroy |
... | ... | @@ -321,7 +323,7 @@ class UploadedFileTest < ActiveSupport::TestCase |
321 | 323 | |
322 | 324 | should 'upload thumbnails to a folder with same name as the schema if database is postgresql' do |
323 | 325 | uses_postgresql |
324 | - file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => @profile) | |
326 | + file = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => @profile) | |
325 | 327 | process_delayed_job_queue |
326 | 328 | UploadedFile.attachment_options[:thumbnails].each do |suffix, size| |
327 | 329 | assert_match(/test_schema\/\d{4}\/\d{4}\/rails_#{suffix}.png/, UploadedFile.find(file.id).public_filename(suffix)) |
... | ... | @@ -331,13 +333,13 @@ class UploadedFileTest < ActiveSupport::TestCase |
331 | 333 | end |
332 | 334 | |
333 | 335 | should 'not allow script files to be uploaded without append .txt in the end' do |
334 | - file = UploadedFile.create!(:uploaded_data => fixture_file_upload('files/hello_world.php', 'application/x-php'), :profile => @profile) | |
336 | + file = create(UploadedFile, :uploaded_data => fixture_file_upload('files/hello_world.php', 'application/x-php'), :profile => @profile) | |
335 | 337 | assert_equal 'hello_world.php.txt', file.filename |
336 | 338 | end |
337 | 339 | |
338 | 340 | should 'use gallery as target for action tracker' do |
339 | 341 | gallery = fast_create(Gallery, :profile_id => profile.id) |
340 | - image = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile) | |
342 | + image = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile) | |
341 | 343 | activity = ActionTracker::Record.find_last_by_verb 'upload_image' |
342 | 344 | assert_equal gallery, activity.target |
343 | 345 | end |
... | ... | @@ -345,10 +347,10 @@ class UploadedFileTest < ActiveSupport::TestCase |
345 | 347 | should 'group trackers activity of image\'s upload' do |
346 | 348 | gallery = fast_create(Gallery, :profile_id => profile.id) |
347 | 349 | |
348 | - image1 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile) | |
350 | + image1 = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile) | |
349 | 351 | assert_equal 1, ActionTracker::Record.find_all_by_verb('upload_image').count |
350 | 352 | |
351 | - image2 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'), :parent => gallery, :profile => profile) | |
353 | + image2 = create(UploadedFile, :uploaded_data => fixture_file_upload('/files/other-pic.jpg', 'image/jpg'), :parent => gallery, :profile => profile) | |
352 | 354 | assert_equal 1, ActionTracker::Record.find_all_by_verb('upload_image').count |
353 | 355 | end |
354 | 356 | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +# Monkey patch to rewrite attachment_fu's logic where no image with parent can | |
2 | +# be thumbnailable. | |
3 | + | |
4 | +Technoweenie::AttachmentFu.module_eval do | |
5 | + def thumbnailable? | |
6 | + image? && !is_thumbnail? | |
7 | + end | |
8 | + | |
9 | + def is_thumbnail? | |
10 | + (thumbnail_class == self.class) && !(respond_to?(:parent_id) && parent_id.nil?) | |
11 | + end | |
12 | +end | |
13 | + | |
14 | +# Monkey patch to rewrite attachment_fu's logic where no image with parent can | |
15 | +# be thumbnailable and supposition that full_filename will return a String | |
16 | +# while it might return Pathname. | |
17 | +Technoweenie::AttachmentFu::Backends::FileSystemBackend.module_eval do | |
18 | + def attachment_path_id | |
19 | + (is_thumbnail? && respond_to?(:parent_id)) ? parent_id : id | |
20 | + end | |
21 | + | |
22 | + def public_filename(thumbnail = nil) | |
23 | + full_filename(thumbnail).to_s.gsub %r(^#{Regexp.escape(base_path)}), '' | |
24 | + end | |
25 | +end | |
26 | + | ... | ... |