compages 0.4.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.
- data/.project +18 -0
- data/README +180 -0
- data/Rakefile +10 -0
- data/app/controllers/application.rb +4 -0
- data/app/controllers/contents_controller.rb +116 -0
- data/app/controllers/pages_controller.rb +59 -0
- data/app/controllers/render_controller.rb +24 -0
- data/app/helpers/application_helper.rb +6 -0
- data/app/helpers/contents_helper.rb +5 -0
- data/app/helpers/pages_helper.rb +5 -0
- data/app/helpers/render_helper.rb +2 -0
- data/app/models/content.rb +26 -0
- data/app/models/meta_data.rb +3 -0
- data/app/models/page.rb +106 -0
- data/app/models/page_element.rb +9 -0
- data/app/views/contents/_content_preview.rhtml +1 -0
- data/app/views/contents/_contents_list.rhtml +3 -0
- data/app/views/contents/_show_library.rhtml +60 -0
- data/app/views/contents/_write_now.rhtml +42 -0
- data/app/views/layouts/pages.rhtml +24 -0
- data/app/views/layouts/render.rhtml +11 -0
- data/app/views/pages/_change_theme.rhtml +0 -0
- data/app/views/pages/_edit_menu.rhtml +62 -0
- data/app/views/pages/_page_listed.rhtml +13 -0
- data/app/views/pages/_select_theme.rhtml +4 -0
- data/app/views/pages/edit.rhtml +35 -0
- data/app/views/pages/index.rhtml +45 -0
- data/app/views/pages/list.rhtml +41 -0
- data/app/views/pages/list_a.rhtml +40 -0
- data/app/views/pages/welcome.rhtml +27 -0
- data/app/views/render/_blank.rhtml +3 -0
- data/app/views/render/show.rhtml +1 -0
- data/bin/compages +14 -0
- data/config/boot.rb +44 -0
- data/config/database.yml.home +35 -0
- data/config/environment.rb +53 -0
- data/config/environments/development.rb +21 -0
- data/config/environments/production.rb +18 -0
- data/config/environments/test.rb +19 -0
- data/config/routes.rb +32 -0
- data/db/Copia di schema.rb +48 -0
- data/db/migrate/001_create_pages.rb +12 -0
- data/db/migrate/002_create_contents.rb +12 -0
- data/db/migrate/003_create_meta_datas.rb +14 -0
- data/db/migrate/004_create_page_elements.rb +17 -0
- data/db/migrate/005_add_urlnames.rb +15 -0
- data/db/migrate/006_add_sessions.rb +15 -0
- data/db/schema.mysql.sql +65 -0
- data/db/schema.postgresql.sql +65 -0
- data/db/schema.rb +49 -0
- data/db/schema.sqlite.sql +65 -0
- data/db/schema.sqlserver.sql +71 -0
- data/db/schema_version +1 -0
- data/doc/ER-model/v1.dia +0 -0
- data/doc/ER-model/v2.dia +0 -0
- data/doc/ER-model/v3.dia +0 -0
- data/doc/README_FOR_APP +2 -0
- data/doc/esempi/doc-vir/ecds.htm +2362 -0
- data/doc/esempi/doc-vir/ecds_files/search.gif +0 -0
- data/doc/esempi/doc-vir/ecds_files/upld.gif +0 -0
- data/doc/esempi/doc-vir/ecds_files/upld.jpg +0 -0
- data/installer/apache13.conf.example.template +33 -0
- data/installer/apache20.conf.example.template +40 -0
- data/installer/lighttpd.conf.example.template +6 -0
- data/installer/rails_installer_defaults.yml +5 -0
- data/lib/redcloth.rb +1130 -0
- data/lib/render_engine.rb +94 -0
- data/lib/tasks/release.rake +46 -0
- data/public/.htaccess +41 -0
- data/public/404.html +8 -0
- data/public/500.html +8 -0
- data/public/_index.html +277 -0
- data/public/favicon.ico +0 -0
- data/public/images/body_bg.gif +0 -0
- data/public/images/body_bg_short.gif +0 -0
- data/public/images/ie_shadow.png +0 -0
- data/public/images/journal_reflex.gif +0 -0
- data/public/images/journal_shadow.gif +0 -0
- data/public/images/logo_journal_small.bmp +0 -0
- data/public/images/logo_journal_small.png +0 -0
- data/public/images/page_edit_shadow.png +0 -0
- data/public/images/restore_bar.png +0 -0
- data/public/images/spinner.gif +0 -0
- data/public/javascripts/application.js +23 -0
- data/public/javascripts/controls.js +815 -0
- data/public/javascripts/dragdrop.js +913 -0
- data/public/javascripts/effects.js +958 -0
- data/public/javascripts/lowpro.js +307 -0
- data/public/javascripts/prototype.js +2006 -0
- data/public/robots.txt +1 -0
- data/public/stylesheets/compages.css +196 -0
- data/public/stylesheets/editing.css +180 -0
- data/public/stylesheets/editing_ie_filth.css +36 -0
- data/public/themes/Doc_basic/_script.js +342 -0
- data/public/themes/Doc_basic/images/Thumbs.db +0 -0
- data/public/themes/Doc_basic/images/search.gif +0 -0
- data/public/themes/Doc_basic/images/upld.gif +0 -0
- data/public/themes/Doc_basic/images/upld.jpg +0 -0
- data/public/themes/Doc_basic/index.html +114 -0
- data/public/themes/Doc_basic/style.css +1743 -0
- data/public/themes/color7boxes/default2.css +42 -0
- data/public/themes/color7boxes/index.html +40 -0
- data/public/themes/prova/index.html +12 -0
- data/public/zDoc/images/search.gif +0 -0
- data/public/zDoc/images/upld.gif +0 -0
- data/public/zDoc/images/upld.jpg +0 -0
- data/public/zDoc/index.html +176 -0
- data/public/zDoc/script.js +342 -0
- data/public/zDoc/style.css +1741 -0
- data/script/about +3 -0
- data/script/breakpointer +3 -0
- data/script/console +3 -0
- data/script/destroy +3 -0
- data/script/generate +3 -0
- data/script/performance/benchmarker +3 -0
- data/script/performance/profiler +3 -0
- data/script/plugin +3 -0
- data/script/process/reaper +3 -0
- data/script/process/spawner +3 -0
- data/script/runner +3 -0
- data/script/server +3 -0
- data/test/fixtures/contents.yml +5 -0
- data/test/fixtures/meta_datas.yml +5 -0
- data/test/fixtures/page_elements.yml +5 -0
- data/test/fixtures/pages.yml +5 -0
- data/test/functional/contents_controller_test.rb +18 -0
- data/test/functional/pages_controller_test.rb +18 -0
- data/test/functional/render_controller_test.rb +18 -0
- data/test/test_helper.rb +28 -0
- data/test/unit/content_test.rb +10 -0
- data/test/unit/meta_data_test.rb +10 -0
- data/test/unit/page_element_test.rb +10 -0
- data/test/unit/page_test.rb +10 -0
- data/tmp/sessions/ruby_sess.0ced4c30e36477ab +0 -0
- data/tmp/sessions/ruby_sess.20fbe26671422e70 +0 -0
- data/tmp/sessions/ruby_sess.2c72521f3a7e2ba9 +0 -0
- data/tmp/sessions/ruby_sess.4107a69d982a2eb7 +0 -0
- data/tmp/sessions/ruby_sess.573ded9c7fdd9035 +0 -0
- data/tmp/sessions/ruby_sess.5a9767815bb96258 +0 -0
- data/tmp/sessions/ruby_sess.85d723b794005388 +0 -0
- data/tmp/sessions/ruby_sess.875b3b3e3529afdb +0 -0
- data/tmp/sessions/ruby_sess.936766f3a397c88b +0 -0
- data/tmp/sessions/ruby_sess.984e2e4c9a2e7891 +0 -0
- data/tmp/sessions/ruby_sess.a1faebd7448bc45d +0 -0
- data/tmp/sessions/ruby_sess.a415768c7635bc15 +0 -0
- data/tmp/sessions/ruby_sess.b2dadcbe6c1b0add +0 -0
- data/tmp/sessions/ruby_sess.ca9100beb103a428 +0 -0
- data/tmp/sessions/ruby_sess.d649c800a046efde +0 -0
- data/tmp/sessions/ruby_sess.db73bbfafd5a537c +0 -0
- data/tmp/sessions/ruby_sess.e32487b847524df1 +0 -0
- data/tmp/sessions/ruby_sess.f4e45d67828cc437 +0 -0
- data/tmp/sessions/ruby_sess.f5a3f064f2f7a26f +0 -0
- data/tmp/sessions/ruby_sess.ff0c47b35f238cda +0 -0
- data/vendor/plugins/acts_as_urlnameable.tar.gz +0 -0
- data/vendor/plugins/acts_as_urlnameable/LICENSE +19 -0
- data/vendor/plugins/acts_as_urlnameable/README +193 -0
- data/vendor/plugins/acts_as_urlnameable/Rakefile +25 -0
- data/vendor/plugins/acts_as_urlnameable/TODO +5 -0
- data/vendor/plugins/acts_as_urlnameable/db/00x_add_urlnames_table.rb +15 -0
- data/vendor/plugins/acts_as_urlnameable/db/urlnames_table.sql +7 -0
- data/vendor/plugins/acts_as_urlnameable/doc/classes/ActiveRecord/Acts/Urlnameable/ClassMethods.html +167 -0
- data/vendor/plugins/acts_as_urlnameable/doc/classes/ActiveRecord/Acts/Urlnameable/InstanceMethods.html +213 -0
- data/vendor/plugins/acts_as_urlnameable/doc/classes/ActiveRecord/Acts/Urlnameable/SingletonMethods.html +189 -0
- data/vendor/plugins/acts_as_urlnameable/doc/created.rid +1 -0
- data/vendor/plugins/acts_as_urlnameable/doc/files/LICENSE.html +129 -0
- data/vendor/plugins/acts_as_urlnameable/doc/files/README.html +333 -0
- data/vendor/plugins/acts_as_urlnameable/doc/files/TODO.html +121 -0
- data/vendor/plugins/acts_as_urlnameable/doc/files/lib/acts_as_urlnameable_rb.html +101 -0
- data/vendor/plugins/acts_as_urlnameable/doc/fr_class_index.html +29 -0
- data/vendor/plugins/acts_as_urlnameable/doc/fr_file_index.html +30 -0
- data/vendor/plugins/acts_as_urlnameable/doc/fr_method_index.html +34 -0
- data/vendor/plugins/acts_as_urlnameable/doc/index.html +24 -0
- data/vendor/plugins/acts_as_urlnameable/doc/rdoc-style.css +208 -0
- data/vendor/plugins/acts_as_urlnameable/init.rb +3 -0
- data/vendor/plugins/acts_as_urlnameable/lib/acts_as_urlnameable.rb +159 -0
- data/vendor/plugins/acts_as_urlnameable/lib/urlname.rb +3 -0
- data/vendor/plugins/acts_as_urlnameable/test/acts_as_urlnameable_test.rb +233 -0
- data/vendor/plugins/acts_as_urlnameable/test/connection.rb +8 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/article.rb +13 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/articles.yml +62 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/page.rb +14 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/pages.yml +35 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/people.yml +9 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/person.rb +26 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/schema.rb +24 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/section.rb +5 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/sections.yml +9 -0
- data/vendor/plugins/acts_as_urlnameable/test/fixtures/urlnames.yml +153 -0
- data/vendor/plugins/acts_as_urlnameable/test/test_helper.rb +42 -0
- data/vendor/plugins/gems/README +30 -0
- data/vendor/plugins/gems/init.rb +9 -0
- data/vendor/plugins/gems/tasks/gems_tasks.rake +32 -0
- data/vendor/plugins/unobtrusive_javascript/CHANGELOG +72 -0
- data/vendor/plugins/unobtrusive_javascript/README +73 -0
- data/vendor/plugins/unobtrusive_javascript/Rakefile +33 -0
- data/vendor/plugins/unobtrusive_javascript/about.yml +6 -0
- data/vendor/plugins/unobtrusive_javascript/assets/javascripts/lowpro.js +307 -0
- data/vendor/plugins/unobtrusive_javascript/init.rb +21 -0
- data/vendor/plugins/unobtrusive_javascript/install.rb +1 -0
- data/vendor/plugins/unobtrusive_javascript/lib/actionview_helpers_patches.rb +17 -0
- data/vendor/plugins/unobtrusive_javascript/lib/asset_tag_helper_patches.rb +33 -0
- data/vendor/plugins/unobtrusive_javascript/lib/behaviour_caching.rb +70 -0
- data/vendor/plugins/unobtrusive_javascript/lib/controllers/unobtrusive_javascript_controller.rb +52 -0
- data/vendor/plugins/unobtrusive_javascript/lib/prototype_helper_patches.rb +72 -0
- data/vendor/plugins/unobtrusive_javascript/lib/scriptaculous_helper_patches.rb +62 -0
- data/vendor/plugins/unobtrusive_javascript/lib/tag_helper_patches.rb +37 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs.rb +32 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/behaviour_helper.rb +62 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/behaviour_script.rb +54 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/behaviour_script_converter.rb +23 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/controller_methods.rb +55 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/helpers.rb +152 -0
- data/vendor/plugins/unobtrusive_javascript/lib/ujs/javascript_proxies.rb +57 -0
- data/vendor/plugins/unobtrusive_javascript/tasks/unobtrusive_javascript_tasks.rake +15 -0
- data/vendor/plugins/unobtrusive_javascript/test/asset_tag_helper_patches_test.rb +32 -0
- data/vendor/plugins/unobtrusive_javascript/test/behaviour_helper_test.rb +180 -0
- data/vendor/plugins/unobtrusive_javascript/test/behaviour_script_converter_test.rb +72 -0
- data/vendor/plugins/unobtrusive_javascript/test/behaviour_script_test.rb +98 -0
- data/vendor/plugins/unobtrusive_javascript/test/config/environment.rb +8 -0
- data/vendor/plugins/unobtrusive_javascript/test/config/routes.rb +4 -0
- data/vendor/plugins/unobtrusive_javascript/test/config/schema.rb +3 -0
- data/vendor/plugins/unobtrusive_javascript/test/controller_methods_test.rb +48 -0
- data/vendor/plugins/unobtrusive_javascript/test/helpers_test.rb +186 -0
- data/vendor/plugins/unobtrusive_javascript/test/javascript_proxies_test.rb +3 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/boot.rb +26 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/action_controller.rb +11 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/action_mailer.rb +4 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/active_record.rb +27 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/gem/rails.rb +31 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/ptk.rb +148 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/ptk/suite/difference.rb +23 -0
- data/vendor/plugins/unobtrusive_javascript/test/lib/stubs/controller_stub.rb +10 -0
- data/vendor/plugins/unobtrusive_javascript/test/ptk_helper.rb +29 -0
- data/vendor/plugins/unobtrusive_javascript/test/tag_helper_patches_test.rb +59 -0
- data/vendor/plugins/unobtrusive_javascript/test/test_helper.rb +25 -0
- data/vendor/plugins/unobtrusive_javascript/test/unobtrusive_javascript_controller_test.rb +95 -0
- data/vendor/plugins/unobtrusive_javascript/uninstall.rb +1 -0
- data/vendor/redcloth/bin/redcloth +3 -0
- data/vendor/redcloth/doc/CHANGELOG +160 -0
- data/vendor/redcloth/doc/COPYING +25 -0
- data/vendor/redcloth/doc/README +106 -0
- data/vendor/redcloth/doc/REFERENCE +216 -0
- data/vendor/redcloth/doc/make.rb +359 -0
- data/vendor/redcloth/lib/redcloth.rb +1130 -0
- data/vendor/redcloth/run-tests.rb +28 -0
- data/vendor/redcloth/setup.rb +1376 -0
- data/vendor/redcloth/tests/code.yml +105 -0
- data/vendor/redcloth/tests/hard_breaks.yml +26 -0
- data/vendor/redcloth/tests/images.yml +171 -0
- data/vendor/redcloth/tests/instiki.yml +39 -0
- data/vendor/redcloth/tests/links.yml +155 -0
- data/vendor/redcloth/tests/lists.yml +77 -0
- data/vendor/redcloth/tests/markdown.yml +218 -0
- data/vendor/redcloth/tests/poignant.yml +64 -0
- data/vendor/redcloth/tests/table.yml +198 -0
- data/vendor/redcloth/tests/textism.yml +406 -0
- metadata +432 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
module ActiveRecord #:nodoc:
|
|
2
|
+
module Acts #:nodoc:
|
|
3
|
+
module Urlnameable #:nodoc:
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.extend(ClassMethods)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
module ClassMethods
|
|
9
|
+
def acts_as_urlnameable(attr_name, options = {})
|
|
10
|
+
|
|
11
|
+
write_inheritable_attribute(:acts_as_urlnameable_options,
|
|
12
|
+
{ :type => ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s,
|
|
13
|
+
:attr => attr_name,
|
|
14
|
+
:mode => (options[:mode] || :single),
|
|
15
|
+
:overwrite => (options[:overwrite] || false),
|
|
16
|
+
:validate => (options[:validate] || :class),
|
|
17
|
+
:owner_association => (options[:owner_association] || nil),
|
|
18
|
+
:message => (options[:message] || 'already exists') } )
|
|
19
|
+
|
|
20
|
+
class_inheritable_reader :acts_as_urlnameable_options
|
|
21
|
+
|
|
22
|
+
write_inheritable_attribute(:urlname_table, Urlname.table_name)
|
|
23
|
+
class_inheritable_reader :urlname_table
|
|
24
|
+
|
|
25
|
+
has_many :urlnames, :as => :nameable, :order => 'id DESC', :dependent => true
|
|
26
|
+
after_save :update_or_add_urlname
|
|
27
|
+
validate :validate_urlname unless acts_as_urlnameable_options[:validate] == false
|
|
28
|
+
|
|
29
|
+
include ActiveRecord::Acts::Urlnameable::InstanceMethods
|
|
30
|
+
extend ActiveRecord::Acts::Urlnameable::SingletonMethods
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
module SingletonMethods
|
|
36
|
+
def find_all_by_urlname(name)
|
|
37
|
+
find_urlnames(name, :all)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def find_by_urlname(name)
|
|
41
|
+
find_urlnames(name, :first)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def urlnames
|
|
45
|
+
connection.select_values("SELECT name FROM #{urlname_table}
|
|
46
|
+
WHERE #{urlname_table}.nameable_type = '#{acts_as_urlnameable_options[:type]}'")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
def find_urlnames(name, all_or_first)
|
|
51
|
+
find( all_or_first,
|
|
52
|
+
:select => "#{table_name}.*",
|
|
53
|
+
:joins => "JOIN #{urlname_table} ON #{table_name}.#{primary_key} = #{urlname_table}.nameable_id",
|
|
54
|
+
:conditions =>
|
|
55
|
+
["#{urlname_table}.nameable_type = '#{acts_as_urlnameable_options[:type]}'
|
|
56
|
+
AND #{urlname_table}.name = ?", name],
|
|
57
|
+
:readonly => false)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
module InstanceMethods
|
|
62
|
+
def urlname
|
|
63
|
+
urlnames.first ? urlnames.first.name : nil
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def past_urlnames
|
|
67
|
+
(urlnames.size <= 1) ? [] : (urlnames - [urlnames.first]).collect { |u| u.name }
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def all_urlnames
|
|
71
|
+
urlnames.collect { |u| u.name }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def urlnameify(text)
|
|
75
|
+
t = text.to_s.downcase.strip.gsub(/[^-_\s[:alnum:]]/, '').squeeze(' ').tr(' ', '_')
|
|
76
|
+
(t.blank?) ? '_' : t
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
private
|
|
80
|
+
def attr_to_urlname
|
|
81
|
+
urlnameify(send(acts_as_urlnameable_options[:attr]))
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def update_or_add_urlname
|
|
85
|
+
recent_name = (urlnames.first || urlnames.build)
|
|
86
|
+
urlname_string = attr_to_urlname
|
|
87
|
+
|
|
88
|
+
case acts_as_urlnameable_options[:mode]
|
|
89
|
+
when :single
|
|
90
|
+
if acts_as_urlnameable_options[:overwrite]
|
|
91
|
+
recent_name.name = urlname_string
|
|
92
|
+
else
|
|
93
|
+
recent_name.name = urlname_string if recent_name.new_record?
|
|
94
|
+
end
|
|
95
|
+
when :multiple
|
|
96
|
+
if recent_name.new_record? && !past_urlnames.include?(urlname_string)
|
|
97
|
+
recent_name.name = urlname_string
|
|
98
|
+
elsif !recent_name.new_record? && !past_urlnames.include?(urlname_string)
|
|
99
|
+
unless recent_name.name == urlname_string
|
|
100
|
+
recent_name = urlnames.build(:name => urlname_string)
|
|
101
|
+
# Because it ends up at the end of the association when it should be at the start
|
|
102
|
+
urlnames.unshift(urlnames.pop)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
recent_name.save
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def validate_urlname
|
|
111
|
+
case acts_as_urlnameable_options[:validate]
|
|
112
|
+
when :class, :sti_class
|
|
113
|
+
validate_urlname_against_class
|
|
114
|
+
else
|
|
115
|
+
validate_urlname_against_owner
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def validate_urlname_against_class
|
|
120
|
+
urlname_string = attr_to_urlname
|
|
121
|
+
|
|
122
|
+
if past_urlnames.include? urlname_string
|
|
123
|
+
return true
|
|
124
|
+
else
|
|
125
|
+
finder_class =
|
|
126
|
+
(acts_as_urlnameable_options[:validate] == :sti_class) ? self.class : acts_as_urlnameable_options[:type].constantize
|
|
127
|
+
|
|
128
|
+
existing_urlname = finder_class.find_by_urlname(urlname_string)
|
|
129
|
+
|
|
130
|
+
if existing_urlname == self || existing_urlname.nil?
|
|
131
|
+
return true
|
|
132
|
+
else
|
|
133
|
+
errors.add(:urlname, acts_as_urlnameable_options[:message])
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def validate_urlname_against_owner
|
|
139
|
+
owner_reflection = self.class.reflect_on_association(acts_as_urlnameable_options[:validate])
|
|
140
|
+
unless owner_reflection && owner_reflection.macro == :belongs_to
|
|
141
|
+
raise ArgumentError, "You can only validate against the class as a whole, or a belongs_to association."
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
unless child_reflection = owner_reflection.klass.reflect_on_association(acts_as_urlnameable_options[:owner_association] || self.class.to_s.tableize.to_sym)
|
|
145
|
+
raise ArgumentError, "Couldn't figure out owner association via reflection"
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
if obj = send(owner_reflection.name).send(child_reflection.name).find_by_urlname(attr_to_urlname)
|
|
149
|
+
errors.add(:urlname, acts_as_urlnameable_options[:message]) unless obj == self || obj.nil?
|
|
150
|
+
else
|
|
151
|
+
return true
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
|
2
|
+
|
|
3
|
+
class ActsAsUrlnameableTest < Test::Unit::TestCase
|
|
4
|
+
fixtures :articles, :pages, :people, :sections, :urlnames
|
|
5
|
+
|
|
6
|
+
def test_urlname_reader_methods
|
|
7
|
+
assert_equal 'first_test_article_edit', articles(:first).urlname
|
|
8
|
+
|
|
9
|
+
assert_nil articles(:sixth).urlname
|
|
10
|
+
|
|
11
|
+
assert_equal 'seventh_test_article', articles(:seventh).urlname
|
|
12
|
+
|
|
13
|
+
assert_equal 'joe_smith', people(:first).urlname
|
|
14
|
+
|
|
15
|
+
assert_equal 'jane_bloggs', people(:second).urlname
|
|
16
|
+
|
|
17
|
+
assert_equal 2, articles(:first).past_urlnames.size
|
|
18
|
+
|
|
19
|
+
assert articles(:first).past_urlnames.find { |u| u == 'first_test_article' }
|
|
20
|
+
|
|
21
|
+
assert_nil articles(:third).past_urlnames.find { |u| u == 'third_test_article' }
|
|
22
|
+
|
|
23
|
+
assert 0, people(:first).past_urlnames.size
|
|
24
|
+
|
|
25
|
+
assert 1, people(:second).past_urlnames.size
|
|
26
|
+
|
|
27
|
+
assert 2, people(:second).all_urlnames.size
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_urlname_association
|
|
31
|
+
assert_equal 3, articles(:first).urlnames.size
|
|
32
|
+
|
|
33
|
+
assert_equal 2, articles(:third).urlnames.size
|
|
34
|
+
|
|
35
|
+
assert_equal 1, people(:first).urlnames.size
|
|
36
|
+
|
|
37
|
+
assert_equal 3, people(:second).urlnames.size
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_urlnames_class_method
|
|
41
|
+
assert_equal Urlname.find_all_by_nameable_type('Article').size, Article.urlnames.size
|
|
42
|
+
|
|
43
|
+
assert_equal Urlname.find_all_by_nameable_type('Person').size, Person.urlnames.size
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_class_finder_methods
|
|
47
|
+
assert_equal articles(:first), Article.find_by_urlname('first_test_article_edit')
|
|
48
|
+
|
|
49
|
+
assert_equal articles(:third), Article.find_by_urlname('old_third_test_title')
|
|
50
|
+
|
|
51
|
+
assert_nil Article.find_by_urlname('blah blah non existent')
|
|
52
|
+
|
|
53
|
+
assert_equal 2, Page.find_all_by_urlname('test_for_multiple_finder').size
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_finder_methods_with_association
|
|
58
|
+
person_one, person_two = people(:first), people(:second)
|
|
59
|
+
|
|
60
|
+
assert_nil person_one.articles.find_by_urlname('blah blah non existent')
|
|
61
|
+
|
|
62
|
+
assert_equal articles(:first), person_one.articles.find_by_urlname('first_test_article_edit')
|
|
63
|
+
|
|
64
|
+
assert_equal articles(:first), person_one.articles.find_by_urlname('first_test_article')
|
|
65
|
+
|
|
66
|
+
assert_equal articles(:fourth), person_two.articles.find_by_urlname('fourth_test_article')
|
|
67
|
+
|
|
68
|
+
assert_nil person_one.articles.find_by_urlname('fourth_test_article')
|
|
69
|
+
|
|
70
|
+
assert_nil person_two.articles.find_by_urlname('first_test_article_edit')
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_urlname_single_saving_without_overwrite
|
|
74
|
+
page = Page.new(:title => 'Testing New Urlnames - Test',
|
|
75
|
+
:body => 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin adipiscing mi ac neque.')
|
|
76
|
+
page.save
|
|
77
|
+
|
|
78
|
+
assert_equal page, Page.find_by_urlname('testing_new_urlnames_-_test')
|
|
79
|
+
|
|
80
|
+
page.title = 'This is another test of the urlname saving'
|
|
81
|
+
|
|
82
|
+
page.save
|
|
83
|
+
|
|
84
|
+
assert_equal page, Page.find_by_urlname('testing_new_urlnames_-_test')
|
|
85
|
+
|
|
86
|
+
assert_nil Page.find_by_urlname('this_is_another_test_of_the_urlname_saving')
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def test_urlname_single_saving_with_overwrite
|
|
90
|
+
section = Section.new(:name => 'Testing Section')
|
|
91
|
+
|
|
92
|
+
section.save
|
|
93
|
+
|
|
94
|
+
assert_equal section, Section.find_by_urlname('testing_section')
|
|
95
|
+
|
|
96
|
+
section.name = 'Renamed this section'
|
|
97
|
+
|
|
98
|
+
section.save
|
|
99
|
+
|
|
100
|
+
assert_nil Section.find_by_urlname('testing_section')
|
|
101
|
+
|
|
102
|
+
assert_equal section, Section.find_by_urlname('renamed_this_section')
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_urlname_multiple_saving
|
|
106
|
+
article = Article.new(:title => 'Testing New Urlnames - Test Article',
|
|
107
|
+
:body => 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin adipiscing mi ac neque.')
|
|
108
|
+
article.save
|
|
109
|
+
|
|
110
|
+
assert_equal article, Article.find_by_urlname('testing_new_urlnames_-_test_article')
|
|
111
|
+
|
|
112
|
+
assert_equal article.urlname, 'testing_new_urlnames_-_test_article'
|
|
113
|
+
|
|
114
|
+
article.title = 'This is another test of the urlname saving - article'
|
|
115
|
+
|
|
116
|
+
article.save
|
|
117
|
+
|
|
118
|
+
assert_equal article.urlname, 'this_is_another_test_of_the_urlname_saving_-_article'
|
|
119
|
+
|
|
120
|
+
assert_equal article, Article.find_by_urlname('this_is_another_test_of_the_urlname_saving_-_article')
|
|
121
|
+
|
|
122
|
+
assert_equal article, Article.find_by_urlname('testing_new_urlnames_-_test_article')
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def test_validations_against_class
|
|
126
|
+
article = Article.new(:title => 'Ninth Test Article',
|
|
127
|
+
:body => 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin adipiscing mi ac neque.')
|
|
128
|
+
|
|
129
|
+
assert !article.save
|
|
130
|
+
|
|
131
|
+
assert_equal 'already exists', article.errors[:urlname]
|
|
132
|
+
|
|
133
|
+
article = articles(:ninth)
|
|
134
|
+
|
|
135
|
+
assert article.save
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def test_validations_against_owner
|
|
139
|
+
page = sections(:ruby).pages.build(:title => 'a test page about rails specifically')
|
|
140
|
+
|
|
141
|
+
assert !page.save
|
|
142
|
+
|
|
143
|
+
assert_equal 'already exists', page.errors[:urlname]
|
|
144
|
+
|
|
145
|
+
Page.send(:acts_as_urlnameable, :title, :validate => :section)
|
|
146
|
+
|
|
147
|
+
page = sections(:ruby).pages.build(:title => 'a test page about rails specifically')
|
|
148
|
+
|
|
149
|
+
assert page.save
|
|
150
|
+
|
|
151
|
+
page = sections(:rails).pages.build(:title => 'a test page about rails specifically')
|
|
152
|
+
|
|
153
|
+
assert !page.save
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def test_with_single_table_inheritance
|
|
157
|
+
press_release = PressRelease.new( :title => 'testing single table inheritance',
|
|
158
|
+
:body => 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin adipiscing mi ac neque.')
|
|
159
|
+
|
|
160
|
+
assert press_release.save
|
|
161
|
+
|
|
162
|
+
assert_equal press_release, Article.find_by_urlname('testing_single_table_inheritance')
|
|
163
|
+
|
|
164
|
+
assert_nil PressRelease.find_by_urlname('first_test_article_edit')
|
|
165
|
+
|
|
166
|
+
assert_not_nil Article.find_by_urlname('first_test_article_edit')
|
|
167
|
+
|
|
168
|
+
press_release = PressRelease.new( :title => 'first test article edit',
|
|
169
|
+
:body => 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin adipiscing mi ac neque.')
|
|
170
|
+
|
|
171
|
+
assert !press_release.save
|
|
172
|
+
|
|
173
|
+
PressRelease.send(:acts_as_urlnameable, :title, :mode => :multiple, :validate => :sti_class)
|
|
174
|
+
|
|
175
|
+
assert press_release.save
|
|
176
|
+
|
|
177
|
+
assert_equal 1, PressRelease.find_all_by_urlname('first_test_article_edit').size
|
|
178
|
+
assert_equal 2, Article.find_all_by_urlname('first_test_article_edit').size
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def test_bad_reflection
|
|
182
|
+
bad_page = BadPage.new( :title => 'Testing bad association validation',
|
|
183
|
+
:body => 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin adipiscing mi ac neque.')
|
|
184
|
+
|
|
185
|
+
assert_raise(ArgumentError) { bad_page.save }
|
|
186
|
+
|
|
187
|
+
badder_page = BadderPage.new( :title => "Testing bad association validation - can't reflect the has_many or has_one association",
|
|
188
|
+
:body => 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin adipiscing mi ac neque.')
|
|
189
|
+
|
|
190
|
+
assert_raise(ArgumentError) { badder_page.save }
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def test_custom_owner_association
|
|
194
|
+
article = people(:first).custom_articles.build( :title => 'Testing custom association validation',
|
|
195
|
+
:body => 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin adipiscing mi ac neque.')
|
|
196
|
+
|
|
197
|
+
assert article.save
|
|
198
|
+
|
|
199
|
+
assert_not_nil SpecialArticle.find_by_urlname('testing_custom_association_validation')
|
|
200
|
+
|
|
201
|
+
article = people(:first).custom_articles.build( :title => 'Testing custom association validation',
|
|
202
|
+
:body => 'This urlname should already exist now')
|
|
203
|
+
|
|
204
|
+
assert !article.save
|
|
205
|
+
|
|
206
|
+
assert_equal 'already exists', article.errors[:urlname]
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def test_finder_scoping
|
|
210
|
+
assert_equal 2, Page.find_all_by_urlname('test_for_multiple_finder').size
|
|
211
|
+
|
|
212
|
+
Page.with_scope(:find => { :conditions => ['section_id = ?', 2] }) do
|
|
213
|
+
assert_equal 1, Page.find_all_by_urlname('test_for_multiple_finder').size
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def test_custom_validator
|
|
218
|
+
person = PersonWithCustomValidation.new(:full_name => 'Hobo Joe')
|
|
219
|
+
|
|
220
|
+
assert !person.save
|
|
221
|
+
|
|
222
|
+
assert_equal "is invalid. You've got it all wrong! I'm not a name, I AM a number!", person.errors[:urlname]
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def test_custom_urlnameify
|
|
226
|
+
writer = Writer.new(:full_name => 'candy', :password => 'password')
|
|
227
|
+
|
|
228
|
+
assert writer.save
|
|
229
|
+
|
|
230
|
+
assert_not_nil Writer.find_by_urlname('writer_candy')
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
print "Using in memory SQLite 3\n"
|
|
2
|
+
require 'logger'
|
|
3
|
+
|
|
4
|
+
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
|
|
5
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
|
6
|
+
load File.dirname(__FILE__) + "/fixtures/schema.rb"
|
|
7
|
+
require File.dirname(__FILE__) + '/../db/00x_add_urlnames_table.rb'
|
|
8
|
+
AddUrlnamesTable.up
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class Article < ActiveRecord::Base
|
|
2
|
+
belongs_to :person
|
|
3
|
+
acts_as_urlnameable :title, :mode => :multiple
|
|
4
|
+
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class PressRelease < Article
|
|
8
|
+
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class SpecialArticle < Article
|
|
12
|
+
acts_as_urlnameable :title, :mode => :multiple, :validate => :person, :owner_association => :custom_articles
|
|
13
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
first:
|
|
2
|
+
id: 1
|
|
3
|
+
title: first test article
|
|
4
|
+
body: this is the first testing article
|
|
5
|
+
person_id: 1
|
|
6
|
+
comments_enabled: 1
|
|
7
|
+
|
|
8
|
+
second:
|
|
9
|
+
id: 2
|
|
10
|
+
title: second test article
|
|
11
|
+
body: this is the second testing article
|
|
12
|
+
person_id: 1
|
|
13
|
+
comments_enabled: 1
|
|
14
|
+
|
|
15
|
+
third:
|
|
16
|
+
id: 3
|
|
17
|
+
title: third test article
|
|
18
|
+
body: this is the third testing article
|
|
19
|
+
person_id: 1
|
|
20
|
+
comments_enabled: 0
|
|
21
|
+
|
|
22
|
+
fourth:
|
|
23
|
+
id: 4
|
|
24
|
+
title: fourth test article
|
|
25
|
+
body: this is the fourth testing article
|
|
26
|
+
person_id: 2
|
|
27
|
+
comments_enabled: 1
|
|
28
|
+
|
|
29
|
+
fifth:
|
|
30
|
+
id: 5
|
|
31
|
+
title: fifth test article
|
|
32
|
+
body: this is the fifth testing article
|
|
33
|
+
person_id: 2
|
|
34
|
+
comments_enabled: 1
|
|
35
|
+
|
|
36
|
+
sixth:
|
|
37
|
+
id: 6
|
|
38
|
+
title: sixth test article
|
|
39
|
+
body: this is the sixth testing article
|
|
40
|
+
person_id: 2
|
|
41
|
+
comments_enabled: 0
|
|
42
|
+
|
|
43
|
+
seventh:
|
|
44
|
+
id: 7
|
|
45
|
+
title: seventh test article
|
|
46
|
+
body: this is the seventh testing article
|
|
47
|
+
person_id: 1
|
|
48
|
+
comments_enabled: 1
|
|
49
|
+
|
|
50
|
+
eighth:
|
|
51
|
+
id: 8
|
|
52
|
+
title: eighth test article
|
|
53
|
+
body: this is the eighth testing article
|
|
54
|
+
person_id: 2
|
|
55
|
+
comments_enabled: 0
|
|
56
|
+
|
|
57
|
+
ninth:
|
|
58
|
+
id: 9
|
|
59
|
+
title: ninth test article
|
|
60
|
+
body: this is the ninth testing article
|
|
61
|
+
person_id: 1
|
|
62
|
+
comments_enabled: 1
|