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