radiant-page_attachments-extension 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. data/.gitignore +5 -0
  2. data/LICENSE +20 -0
  3. data/README.md +129 -0
  4. data/Rakefile +57 -0
  5. data/VERSION +1 -0
  6. data/app/models/observe_page_attachments.rb +5 -0
  7. data/app/models/page_attachment.rb +28 -0
  8. data/app/models/page_attachment_associations.rb +20 -0
  9. data/app/models/page_attachment_tags.rb +261 -0
  10. data/app/models/page_attachments_interface.rb +19 -0
  11. data/app/views/admin/pages/_attachment.html.haml +12 -0
  12. data/app/views/admin/pages/_attachments_box.html.haml +12 -0
  13. data/db/migrate/001_create_page_attachments_extension_schema.rb +22 -0
  14. data/db/migrate/002_add_page_attachments_fields.rb +23 -0
  15. data/features/attachments.feature +42 -0
  16. data/features/step_definitions/attachment_steps.rb +61 -0
  17. data/features/support/env.rb +57 -0
  18. data/features/support/paths.rb +14 -0
  19. data/lib/difference_test_helper.rb +20 -0
  20. data/lib/radiant-page_attachments-extension.rb +0 -0
  21. data/lib/tasks/page_attachments_extension_tasks.rake +28 -0
  22. data/page_attachments_extension.rb +27 -0
  23. data/public/images/admin/drag_order.png +0 -0
  24. data/public/javascripts/admin/page_attachments.js +30 -0
  25. data/public/stylesheets/admin/page_attachments.css +133 -0
  26. data/radiant-page_attachments-extension.gemspec +139 -0
  27. data/spec/controllers/pages_controller_spec.rb +10 -0
  28. data/spec/datasets/page_attachments_dataset.rb +31 -0
  29. data/spec/fixtures/foo.txt +1 -0
  30. data/spec/fixtures/rails.png +0 -0
  31. data/spec/models/observe_page_attachments_spec.rb +14 -0
  32. data/spec/models/page_attachment_spec.rb +18 -0
  33. data/spec/models/page_attachment_tags_spec.rb +172 -0
  34. data/spec/models/page_spec.rb +32 -0
  35. data/spec/spec.opts +6 -0
  36. data/spec/spec_helper.rb +39 -0
  37. data/vendor/plugins/acts_as_list/README +23 -0
  38. data/vendor/plugins/acts_as_list/init.rb +3 -0
  39. data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
  40. data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
  41. data/vendor/plugins/attachment_fu/CHANGELOG +35 -0
  42. data/vendor/plugins/attachment_fu/LICENSE +20 -0
  43. data/vendor/plugins/attachment_fu/README +193 -0
  44. data/vendor/plugins/attachment_fu/Rakefile +22 -0
  45. data/vendor/plugins/attachment_fu/amazon_s3.yml.tpl +17 -0
  46. data/vendor/plugins/attachment_fu/init.rb +16 -0
  47. data/vendor/plugins/attachment_fu/install.rb +7 -0
  48. data/vendor/plugins/attachment_fu/lib/geometry.rb +93 -0
  49. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/cloud_file_backend.rb +211 -0
  50. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb +39 -0
  51. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb +126 -0
  52. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb +394 -0
  53. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/core_image_processor.rb +59 -0
  54. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/gd2_processor.rb +54 -0
  55. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/image_science_processor.rb +61 -0
  56. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb +132 -0
  57. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb +57 -0
  58. data/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb +514 -0
  59. data/vendor/plugins/attachment_fu/rackspace_cloudfiles.yml.tpl +14 -0
  60. data/vendor/plugins/attachment_fu/test/backends/db_file_test.rb +16 -0
  61. data/vendor/plugins/attachment_fu/test/backends/file_system_test.rb +143 -0
  62. data/vendor/plugins/attachment_fu/test/backends/remote/cloudfiles_test.rb +102 -0
  63. data/vendor/plugins/attachment_fu/test/backends/remote/s3_test.rb +119 -0
  64. data/vendor/plugins/attachment_fu/test/base_attachment_tests.rb +77 -0
  65. data/vendor/plugins/attachment_fu/test/basic_test.rb +70 -0
  66. data/vendor/plugins/attachment_fu/test/database.yml +18 -0
  67. data/vendor/plugins/attachment_fu/test/extra_attachment_test.rb +67 -0
  68. data/vendor/plugins/attachment_fu/test/fixtures/attachment.rb +226 -0
  69. data/vendor/plugins/attachment_fu/test/fixtures/files/fake/rails.png +0 -0
  70. data/vendor/plugins/attachment_fu/test/fixtures/files/foo.txt +1 -0
  71. data/vendor/plugins/attachment_fu/test/fixtures/files/rails.png +0 -0
  72. data/vendor/plugins/attachment_fu/test/geometry_test.rb +108 -0
  73. data/vendor/plugins/attachment_fu/test/processors/core_image_test.rb +37 -0
  74. data/vendor/plugins/attachment_fu/test/processors/gd2_test.rb +31 -0
  75. data/vendor/plugins/attachment_fu/test/processors/image_science_test.rb +31 -0
  76. data/vendor/plugins/attachment_fu/test/processors/mini_magick_test.rb +103 -0
  77. data/vendor/plugins/attachment_fu/test/processors/rmagick_test.rb +255 -0
  78. data/vendor/plugins/attachment_fu/test/schema.rb +134 -0
  79. data/vendor/plugins/attachment_fu/test/test_helper.rb +150 -0
  80. data/vendor/plugins/attachment_fu/test/validation_test.rb +55 -0
  81. data/vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/color.rb +27 -0
  82. data/vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/effects.rb +31 -0
  83. data/vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/perspective.rb +25 -0
  84. data/vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/quality.rb +25 -0
  85. data/vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/scale.rb +47 -0
  86. data/vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/watermark.rb +32 -0
  87. data/vendor/plugins/attachment_fu/vendor/red_artisan/core_image/processor.rb +123 -0
  88. metadata +178 -0
@@ -0,0 +1,139 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{radiant-page_attachments-extension}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Sean Cribbs"]
12
+ s.date = %q{2010-04-29}
13
+ s.description = %q{Page Attachments adds support for file uploads realized as attachments to individual pages. Attachments can have an order via acts_as_list, a title, a description and various metadata fields as provided by AttachmentFu.}
14
+ s.email = %q{radiant@radiantcms.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "app/models/observe_page_attachments.rb",
26
+ "app/models/page_attachment.rb",
27
+ "app/models/page_attachment_associations.rb",
28
+ "app/models/page_attachment_tags.rb",
29
+ "app/models/page_attachments_interface.rb",
30
+ "app/views/admin/pages/_attachment.html.haml",
31
+ "app/views/admin/pages/_attachments_box.html.haml",
32
+ "db/migrate/001_create_page_attachments_extension_schema.rb",
33
+ "db/migrate/002_add_page_attachments_fields.rb",
34
+ "features/attachments.feature",
35
+ "features/step_definitions/attachment_steps.rb",
36
+ "features/support/env.rb",
37
+ "features/support/paths.rb",
38
+ "lib/difference_test_helper.rb",
39
+ "lib/radiant-page_attachments-extension.rb",
40
+ "lib/tasks/page_attachments_extension_tasks.rake",
41
+ "page_attachments_extension.rb",
42
+ "public/images/admin/drag_order.png",
43
+ "public/javascripts/admin/page_attachments.js",
44
+ "public/stylesheets/admin/page_attachments.css",
45
+ "radiant-page_attachments-extension.gemspec",
46
+ "spec/controllers/pages_controller_spec.rb",
47
+ "spec/datasets/page_attachments_dataset.rb",
48
+ "spec/fixtures/foo.txt",
49
+ "spec/fixtures/rails.png",
50
+ "spec/models/observe_page_attachments_spec.rb",
51
+ "spec/models/page_attachment_spec.rb",
52
+ "spec/models/page_attachment_tags_spec.rb",
53
+ "spec/models/page_spec.rb",
54
+ "spec/spec.opts",
55
+ "spec/spec_helper.rb",
56
+ "vendor/plugins/acts_as_list/README",
57
+ "vendor/plugins/acts_as_list/init.rb",
58
+ "vendor/plugins/acts_as_list/lib/active_record/acts/list.rb",
59
+ "vendor/plugins/acts_as_list/test/list_test.rb",
60
+ "vendor/plugins/attachment_fu/CHANGELOG",
61
+ "vendor/plugins/attachment_fu/LICENSE",
62
+ "vendor/plugins/attachment_fu/README",
63
+ "vendor/plugins/attachment_fu/Rakefile",
64
+ "vendor/plugins/attachment_fu/amazon_s3.yml.tpl",
65
+ "vendor/plugins/attachment_fu/init.rb",
66
+ "vendor/plugins/attachment_fu/install.rb",
67
+ "vendor/plugins/attachment_fu/lib/geometry.rb",
68
+ "vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb",
69
+ "vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/cloud_file_backend.rb",
70
+ "vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/db_file_backend.rb",
71
+ "vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb",
72
+ "vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/s3_backend.rb",
73
+ "vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/core_image_processor.rb",
74
+ "vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/gd2_processor.rb",
75
+ "vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/image_science_processor.rb",
76
+ "vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb",
77
+ "vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/rmagick_processor.rb",
78
+ "vendor/plugins/attachment_fu/rackspace_cloudfiles.yml.tpl",
79
+ "vendor/plugins/attachment_fu/test/backends/db_file_test.rb",
80
+ "vendor/plugins/attachment_fu/test/backends/file_system_test.rb",
81
+ "vendor/plugins/attachment_fu/test/backends/remote/cloudfiles_test.rb",
82
+ "vendor/plugins/attachment_fu/test/backends/remote/s3_test.rb",
83
+ "vendor/plugins/attachment_fu/test/base_attachment_tests.rb",
84
+ "vendor/plugins/attachment_fu/test/basic_test.rb",
85
+ "vendor/plugins/attachment_fu/test/database.yml",
86
+ "vendor/plugins/attachment_fu/test/extra_attachment_test.rb",
87
+ "vendor/plugins/attachment_fu/test/fixtures/attachment.rb",
88
+ "vendor/plugins/attachment_fu/test/fixtures/files/fake/rails.png",
89
+ "vendor/plugins/attachment_fu/test/fixtures/files/foo.txt",
90
+ "vendor/plugins/attachment_fu/test/fixtures/files/rails.png",
91
+ "vendor/plugins/attachment_fu/test/geometry_test.rb",
92
+ "vendor/plugins/attachment_fu/test/processors/core_image_test.rb",
93
+ "vendor/plugins/attachment_fu/test/processors/gd2_test.rb",
94
+ "vendor/plugins/attachment_fu/test/processors/image_science_test.rb",
95
+ "vendor/plugins/attachment_fu/test/processors/mini_magick_test.rb",
96
+ "vendor/plugins/attachment_fu/test/processors/rmagick_test.rb",
97
+ "vendor/plugins/attachment_fu/test/schema.rb",
98
+ "vendor/plugins/attachment_fu/test/test_helper.rb",
99
+ "vendor/plugins/attachment_fu/test/validation_test.rb",
100
+ "vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/color.rb",
101
+ "vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/effects.rb",
102
+ "vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/perspective.rb",
103
+ "vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/quality.rb",
104
+ "vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/scale.rb",
105
+ "vendor/plugins/attachment_fu/vendor/red_artisan/core_image/filters/watermark.rb",
106
+ "vendor/plugins/attachment_fu/vendor/red_artisan/core_image/processor.rb"
107
+ ]
108
+ s.homepage = %q{http://github.com/radiant/radiant-page-attachments-extension}
109
+ s.rdoc_options = ["--charset=UTF-8"]
110
+ s.require_paths = ["lib"]
111
+ s.rubygems_version = %q{1.3.6}
112
+ s.summary = %q{Adds page-attachment-style asset management.}
113
+ s.test_files = [
114
+ "spec/controllers/pages_controller_spec.rb",
115
+ "spec/datasets/page_attachments_dataset.rb",
116
+ "spec/models/observe_page_attachments_spec.rb",
117
+ "spec/models/page_attachment_spec.rb",
118
+ "spec/models/page_attachment_tags_spec.rb",
119
+ "spec/models/page_spec.rb",
120
+ "spec/spec_helper.rb"
121
+ ]
122
+
123
+ if s.respond_to? :specification_version then
124
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
125
+ s.specification_version = 3
126
+
127
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
128
+ s.add_development_dependency(%q<rspec>, [">= 0"])
129
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
130
+ else
131
+ s.add_dependency(%q<rspec>, [">= 0"])
132
+ s.add_dependency(%q<cucumber>, [">= 0"])
133
+ end
134
+ else
135
+ s.add_dependency(%q<rspec>, [">= 0"])
136
+ s.add_dependency(%q<cucumber>, [">= 0"])
137
+ end
138
+ end
139
+
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Admin::PagesController do
4
+ dataset :users, :pages
5
+
6
+ before :each do
7
+ login_as :existing
8
+ end
9
+
10
+ end
@@ -0,0 +1,31 @@
1
+ class PageAttachmentsDataset < Dataset::Base
2
+ uses :pages, :users
3
+
4
+ def load
5
+ create_page_attachment "rails.png", :title => "Rails logo", :content_type => "image/png", :width => 50, :height => 64, :description => "The awesome Rails logo."
6
+ create_page_attachment "foo.txt", :title => "Simple text file", :content_type => "text/plain", :description => "Nice shootin', text."
7
+ end
8
+
9
+ helpers do
10
+ def create_page_attachment(filename, attributes={})
11
+ create_record :page_attachment, filename.symbolize, page_attachment_params(attributes.reverse_merge(:filename => filename))
12
+ end
13
+
14
+ def page_attachment_params(attributes={})
15
+ page = pages(:home)
16
+ {
17
+ :size => File.join(File.dirname(__FILE__), '/../fixtures/', attributes[:filename]).size,
18
+ :page => page,
19
+ :position => next_position(page),
20
+ :created_by => users(:admin)
21
+ }.merge(attributes)
22
+ end
23
+
24
+ private
25
+
26
+ def next_position(page)
27
+ (page.attachments.maximum(:position) || 0) + 1
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1 @@
1
+ foo
Binary file
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe UserActionObserver do
4
+
5
+ it "should include ObservePageAttachments" do
6
+ UserActionObserver.included_modules.should include(ObservePageAttachments)
7
+ end
8
+
9
+ it "should include the observed_class method" do
10
+ UserActionObserver.methods.should include('observed_class')
11
+ end
12
+
13
+ end
14
+
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe PageAttachment do
4
+ dataset :pages, :page_attachments
5
+
6
+ it "should change position when first attachment is moved lower" do
7
+ img = page_attachments(:rails_png)
8
+ txt = page_attachments(:foo_txt)
9
+
10
+ img.position.should == 1
11
+ txt.position.should == 2
12
+ img.move_lower
13
+ txt.reload
14
+ img.position.should == 2
15
+ txt.position.should == 1
16
+ end
17
+
18
+ end
@@ -0,0 +1,172 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "page attachment tags" do
4
+ dataset :pages, :page_attachments
5
+
6
+ it "should raise an error when required attributes missing" do
7
+ [:url, :content_type, :size, :width, :height, :date, :image, :link, :author, :title].each do |key|
8
+ message = "'name' attribute required"
9
+ page.should render("<r:attachment:#{key} />").with_error(message)
10
+ end
11
+ end
12
+
13
+ it "<r:attachment /> should render nothing when empty" do
14
+ page.should render("<r:attachment></r:attachment>").as("")
15
+ end
16
+
17
+ it "should render the URL tag" do
18
+ page.should render('<r:attachment:url name="rails.png" />').as(img.public_filename)
19
+ end
20
+ it "should render the title tag" do
21
+ page.should render('<r:attachment:title name="rails.png" />').as(img.title)
22
+ end
23
+ it "should render the content type" do
24
+ page.should render('<r:attachment:content_type name="rails.png" />').as(img.content_type)
25
+ end
26
+
27
+ it "should render the size" do
28
+ page.should render('<r:attachment:size name="rails.png" />').as(img.size.to_s)
29
+ end
30
+ it "should render the size in bytes when unit is invalid" do
31
+ page.should render('<r:attachment:size name="rails.png" units="blargobytes" />').as(img.size.to_s)
32
+ end
33
+ it "should render the size in the units specified" do
34
+ page.should render('<r:attachment:size name="rails.png" units="kilobytes" />').as('%.2f' % (img.size / 1024.00))
35
+ end
36
+
37
+ it "should render the width" do
38
+ page.should render('<r:attachment:width name="rails.png" />').as(img.width.to_s)
39
+ end
40
+ it "should render the height" do
41
+ page.should render('<r:attachment:height name="rails.png" />').as(img.height.to_s)
42
+ end
43
+ it "should render the date" do
44
+ page.should render('<r:attachment:date name="rails.png" format="%Y-%m-%d" />').as(img.created_at.strftime("%Y-%m-%d"))
45
+ end
46
+ it "should render the author" do
47
+ page.should render('<r:attachment:author name="rails.png" />').as(img.created_by.name)
48
+ end
49
+ it "should render empty width and height for non-images" do
50
+ page.should render('<r:attachment:height name="foo.txt"/>').as("")
51
+ page.should render('<r:attachment:width name="foo.txt"/>').as("")
52
+ end
53
+
54
+ it "should render image tag" do
55
+ page.should render('<r:attachment:image name="rails.png" />').as(%{<img src="#{img.public_filename}" />})
56
+ end
57
+ it "should render image tag with HTML attributes" do
58
+ page.should render('<r:attachment:image name="rails.png" style="float: right;"/>').as(%{<img src="#{img.public_filename}" style="float: right;" />})
59
+ end
60
+ it "should render link tag" do
61
+ page.should render('<r:attachment:link name="rails.png" />').as(%{<a href="#{img.public_filename}">rails.png</a>})
62
+ end
63
+ it "should render link tag with HTML attributes" do
64
+ page.should render('<r:attachment:link name="rails.png" id="mylink" />').as(%{<a href="#{img.public_filename}" id="mylink">rails.png</a>})
65
+ end
66
+ it "should render link tag" do
67
+ page.should render('<r:attachment:link name="rails.png">Rails</r:attachment:link>').as(%{<a href="#{img.public_filename}">Rails</a>})
68
+ end
69
+ it "should render link tag with HTML attributes" do
70
+ page.should render('<r:attachment:link name="rails.png" label="Rails"/>').as(%{<a href="#{img.public_filename}">Rails</a>})
71
+ end
72
+
73
+ it "should render the title" do
74
+ page.should render('<r:attachment:title name="rails.png"/>').as(%{Rails logo})
75
+ end
76
+ it "should render the short title" do
77
+ page.should render('<r:attachment:short_title name="rails.png"/>').as(%{Rails logo})
78
+ end
79
+ it "should render the description" do
80
+ page.should render('<r:attachment:description name="rails.png"/>').as(%{The awesome Rails logo.})
81
+ end
82
+ it "should render the short description" do
83
+ page.should render('<r:attachment:short_description name="rails.png"/>').as(%{The awesome ...})
84
+ end
85
+ it "should render the short description at the specified length" do
86
+ page.should render('<r:attachment:short_description name="rails.png" length="13" />').as(%{The aweso ...})
87
+ end
88
+ it "should render the short description at a length greater than the description length" do
89
+ page.should render('<r:attachment:short_description name="rails.png" length="35" />').as(%{The awesome Rails logo.})
90
+ end
91
+ it "should render the short description with a custom length and suffix" do
92
+ page.should render('<r:attachment:short_description name="rails.png" length="15" suffix="...." />').as(%{The awesome....})
93
+ end
94
+ it "should render the filename" do
95
+ page.should render('<r:attachment:filename name="rails.png"/>').as(%{rails.png})
96
+ end
97
+ it "should render the short filename" do
98
+ page.should render('<r:attachment:short_filename name="rails.png"/>').as(%{rails.png})
99
+ end
100
+ it "should render the short filename with a custom length and suffix" do
101
+ page.should render('<r:attachment:short_filename name="rails.png" suffix="..." length="8" />').as(%{rails...})
102
+ end
103
+
104
+ it "should render error when image tag used on non-image" do
105
+ page.should render('<r:attachment:image name="foo.txt" />').with_error("attachment is not an image.")
106
+ end
107
+
108
+ it "should render the contents for each attachment" do
109
+ page.should render("<r:attachment:each>* </r:attachment:each>").as("* * ")
110
+ end
111
+ it "should render contained tags for each attachment" do
112
+ page.should render(%{<r:attachment:each by="filename"><r:link/></r:attachment:each>}).as(%{<a href="#{txt.public_filename}">foo.txt</a><a href="#{img.public_filename}">rails.png</a>})
113
+ end
114
+
115
+ it "should render the contents for each attachment with offset and limit" do
116
+ page.should render(%{<r:attachment:each limit="1" offset="1" by="filename"><r:link/></r:attachment:each>}).as(%{<a href="#{img.public_filename}">rails.png</a>})
117
+ end
118
+ it "should render the contents for each attachment with limit, offset, and order column" do
119
+ page.should render(%{<r:attachment:each limit="1" offset="0" by="filename"><r:link/></r:attachment:each>}).as(%{<a href="#{txt.public_filename}">foo.txt</a>})
120
+ end
121
+ it "should render the contents for each attachment with limit and order column" do
122
+ page.should render(%{<r:attachment:each limit="1" by="filename"><r:link/></r:attachment:each>}).as(%{<a href="#{txt.public_filename}">foo.txt</a>})
123
+ end
124
+ it "should render the contents for each attachment with offset and order column" do
125
+ page.should render(%{<r:attachment:each offset="1" by="filename"><r:link/></r:attachment:each>}).as(%{<a href="#{img.public_filename}">rails.png</a>})
126
+ end
127
+
128
+ it "should filter attachments by extension" do
129
+ page.should render(%{<r:attachment:each extensions="png"><r:filename/></r:attachment:each>}).as("rails.png")
130
+ end
131
+ it "should filter attachments by multiple extensions" do
132
+ page.should render(%{<r:attachment:each extensions="png|txt"><r:filename/></r:attachment:each>}).as("rails.pngfoo.txt")
133
+ end
134
+
135
+ it "should render if attachments" do
136
+ page.should render(%{<r:if_attachments>content</r:if_attachments>}).as("content")
137
+ end
138
+ it "should only render if has the minimum attachments" do
139
+ page.should render(%{<r:if_attachments min_count="3">content</r:if_attachments>}).as("")
140
+ end
141
+ it "should only render if has the minimum attachments with the specified extension" do
142
+ page.should render(%{<r:if_attachments min_count="1" extensions="png">content</r:if_attachments>}).as("content")
143
+ end
144
+
145
+ it "should render the extension" do
146
+ page.should render(%{<r:attachment:each><r:extension/></r:attachment:each>}).as("pngtxt")
147
+ end
148
+
149
+
150
+ it "should render an attachment inherited from the parent" do
151
+ child_page = pages(:first)
152
+ child_page.should render('<r:attachment:url name="rails.png" />').as(img.public_filename)
153
+ child_page.should render('<r:attachment:url name="foo.txt" />').as(txt.public_filename)
154
+ end
155
+
156
+ private
157
+
158
+ def page(symbol = nil)
159
+ if symbol.nil?
160
+ @page ||= pages(:home)
161
+ else
162
+ @page = pages(symbol)
163
+ end
164
+ end
165
+ def img
166
+ page_attachments(:rails_png)
167
+ end
168
+ def txt
169
+ page_attachments(:foo_txt)
170
+ end
171
+
172
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Page, 'page attachments' do
4
+ dataset :pages, :page_attachments
5
+
6
+ it "should include page attachment modules" do
7
+ Page.included_modules.should include(PageAttachmentTags)
8
+ Page.included_modules.should include(PageAttachmentAssociations)
9
+ end
10
+
11
+ it "should have attachment methods" do
12
+ Page.instance_methods.should include("attachments")
13
+ Page.instance_methods.should include("attachments=")
14
+ Page.instance_methods.should include("attachment")
15
+
16
+ Page.instance_methods.should include("tag:attachment")
17
+ [:content_type, :size, :width, :height, :date, :image, :link, :author, :title, :short_title, :short_description, :short_filename, :description, :position].each do |key|
18
+ Page.instance_methods.should include("tag:attachment:#{key}")
19
+ end
20
+ end
21
+
22
+ it "should receive nested attributes for attachments" do
23
+ page = pages(:home)
24
+ page.attachments.length.should == 2
25
+ file =
26
+
27
+ page.attachments_attributes = [{:uploaded_data => fixture_file_upload("#{PageAttachmentsExtension.root}/spec/fixtures/rails.png", 'image/png')}]
28
+ page.save!
29
+ page.reload.attachments.length.should == 1
30
+ end
31
+
32
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,39 @@
1
+ unless defined? RADIANT_ROOT
2
+ ENV["RAILS_ENV"] = "test"
3
+ case
4
+ when ENV["RADIANT_ENV_FILE"]
5
+ require ENV["RADIANT_ENV_FILE"]
6
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
7
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
8
+ else
9
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
10
+ end
11
+ end
12
+ require "#{RADIANT_ROOT}/spec/spec_helper"
13
+
14
+ require 'webrat'
15
+
16
+ Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
17
+
18
+ if File.directory?(File.dirname(__FILE__) + "/matchers")
19
+ Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
20
+ end
21
+
22
+ Spec::Runner.configure do |config|
23
+ # config.use_transactional_fixtures = true
24
+ # config.use_instantiated_fixtures = false
25
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
26
+
27
+ # You can declare fixtures for each behaviour like this:
28
+ # describe "...." do
29
+ # fixtures :table_a, :table_b
30
+ #
31
+ # Alternatively, if you prefer to declare them only once, you can
32
+ # do so here, like so ...
33
+ #
34
+ # config.global_fixtures = :table_a, :table_b
35
+ #
36
+ # If you declare global fixtures, be aware that they will be declared
37
+ # for all of your examples, even those that don't use them.
38
+ config.include Webrat::Matchers, :type => [:views]
39
+ end