parlement 0.10 → 0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/CHANGES +11 -0
  2. data/MEMORY +9 -1
  3. data/README +5 -4
  4. data/app/controllers/account_controller.rb +10 -13
  5. data/app/controllers/application.rb +4 -5
  6. data/app/controllers/elt_controller.rb +9 -7
  7. data/app/controllers/person_controller.rb +1 -3
  8. data/app/controllers/subscriber_controller.rb +10 -10
  9. data/app/helpers/elt_helper.rb +2 -0
  10. data/app/models/elt.rb +28 -19
  11. data/app/models/mail.rb +26 -14
  12. data/app/models/mail_notify.rb +5 -4
  13. data/app/models/person.rb +11 -2
  14. data/app/views/account/_login.rhtml +3 -3
  15. data/app/views/account/_show.rhtml +12 -14
  16. data/app/views/elt/_choice.rhtml +3 -3
  17. data/app/views/elt/_elt.rhtml +4 -4
  18. data/app/views/elt/_list.rhtml +2 -2
  19. data/app/views/elt/_listByDate.rhtml +1 -1
  20. data/app/views/elt/_listByVote.rhtml +1 -1
  21. data/app/views/elt/new.rhtml +3 -3
  22. data/app/views/elt/show.rhtml +2 -2
  23. data/app/views/layouts/top.rhtml +6 -0
  24. data/app/views/mail_notify/publish.text.html.rhtml +1 -1
  25. data/app/views/person/_listElts.rhtml +5 -3
  26. data/app/views/person/show.rhtml +1 -2
  27. data/config/boot.rb +5 -4
  28. data/config/environment.rb +6 -4
  29. data/config/routes.rb +3 -2
  30. data/db/development_structure.sql +15 -4
  31. data/db/migrate/006_last_activity.rb +10 -0
  32. data/db/schema.rb +67 -49
  33. data/public/dispatch.fcgi +1 -0
  34. data/public/javascripts/controls.js +41 -23
  35. data/public/javascripts/dragdrop.js +317 -99
  36. data/public/javascripts/effects.js +301 -166
  37. data/public/javascripts/prototype.js +932 -402
  38. data/public/stylesheets/default.css +3 -2
  39. data/test/unit/elt_test.rb +13 -0
  40. data/test/unit/mail_test.rb +3 -1
  41. data/vendor/plugins/engines/CHANGELOG +203 -99
  42. data/vendor/plugins/engines/MIT-LICENSE +1 -1
  43. data/vendor/plugins/engines/README +32 -384
  44. data/vendor/plugins/engines/Rakefile +14 -0
  45. data/vendor/plugins/engines/UPGRADING +93 -0
  46. data/vendor/plugins/engines/about.yml +7 -0
  47. data/vendor/plugins/engines/generators/plugin_migration/USAGE +45 -0
  48. data/vendor/plugins/engines/generators/plugin_migration/plugin_migration_generator.rb +79 -0
  49. data/vendor/plugins/engines/generators/plugin_migration/templates/plugin_migration.erb +13 -0
  50. data/vendor/plugins/engines/init.rb +34 -47
  51. data/vendor/plugins/engines/install.rb +32 -0
  52. data/vendor/plugins/engines/lib/engines/{ruby_extensions.rb → deprecated_config_support.rb} +135 -113
  53. data/vendor/plugins/engines/lib/engines/plugin.rb +214 -0
  54. data/vendor/plugins/engines/lib/engines/plugin_list.rb +31 -0
  55. data/vendor/plugins/engines/lib/engines/plugin_migrator.rb +60 -0
  56. data/vendor/plugins/engines/lib/engines/rails_extensions/active_record.rb +19 -0
  57. data/vendor/plugins/engines/lib/engines/rails_extensions/dependencies.rb +143 -0
  58. data/vendor/plugins/engines/lib/engines/rails_extensions/migrations.rb +155 -0
  59. data/vendor/plugins/engines/lib/engines/rails_extensions/public_asset_helpers.rb +116 -0
  60. data/vendor/plugins/engines/lib/engines/rails_extensions/rails.rb +20 -0
  61. data/vendor/plugins/engines/lib/engines/rails_extensions/rails_initializer.rb +86 -0
  62. data/vendor/plugins/engines/lib/engines/rails_extensions/routing.rb +77 -0
  63. data/vendor/plugins/engines/lib/engines/rails_extensions/templates.rb +140 -0
  64. data/vendor/plugins/engines/lib/engines/rails_extensions.rb +6 -0
  65. data/vendor/plugins/engines/lib/engines/testing.rb +88 -0
  66. data/vendor/plugins/engines/lib/engines.rb +281 -425
  67. data/vendor/plugins/engines/tasks/engines.rake +108 -137
  68. metadata +218 -250
  69. data/db/ROOT/perso.txt +0 -214
  70. data/public/images/indicator.gif +0 -0
  71. data/public/images/orange_by_darren_Hester_350o.jpg +0 -0
  72. data/public/images/smile.png +0 -0
  73. data/vendor/plugins/engines/generators/engine/USAGE +0 -26
  74. data/vendor/plugins/engines/generators/engine/engine_generator.rb +0 -199
  75. data/vendor/plugins/engines/generators/engine/templates/README +0 -85
  76. data/vendor/plugins/engines/generators/engine/templates/init_engine.erb +0 -15
  77. data/vendor/plugins/engines/generators/engine/templates/install.erb +0 -4
  78. data/vendor/plugins/engines/generators/engine/templates/lib/engine.erb +0 -6
  79. data/vendor/plugins/engines/generators/engine/templates/licenses/GPL +0 -18
  80. data/vendor/plugins/engines/generators/engine/templates/licenses/LGPL +0 -19
  81. data/vendor/plugins/engines/generators/engine/templates/licenses/MIT +0 -22
  82. data/vendor/plugins/engines/generators/engine/templates/licenses/None +0 -1
  83. data/vendor/plugins/engines/generators/engine/templates/public/javascripts/engine.js +0 -0
  84. data/vendor/plugins/engines/generators/engine/templates/public/stylesheets/engine.css +0 -0
  85. data/vendor/plugins/engines/generators/engine/templates/tasks/engine.rake +0 -0
  86. data/vendor/plugins/engines/generators/engine/templates/test/test_helper.erb +0 -17
  87. data/vendor/plugins/engines/lib/bundles/require_resource.rb +0 -124
  88. data/vendor/plugins/engines/lib/bundles.rb +0 -77
  89. data/vendor/plugins/engines/lib/engines/action_mailer_extensions.rb +0 -140
  90. data/vendor/plugins/engines/lib/engines/action_view_extensions.rb +0 -141
  91. data/vendor/plugins/engines/lib/engines/active_record_extensions.rb +0 -21
  92. data/vendor/plugins/engines/lib/engines/dependencies_extensions.rb +0 -129
  93. data/vendor/plugins/engines/lib/engines/migration_extensions.rb +0 -53
  94. data/vendor/plugins/engines/lib/engines/routing_extensions.rb +0 -28
  95. data/vendor/plugins/engines/lib/engines/testing_extensions.rb +0 -327
  96. data/vendor/plugins/engines/tasks/deprecated_engines.rake +0 -7
  97. data/vendor/plugins/engines/test/action_view_extensions_test.rb +0 -9
  98. data/vendor/plugins/engines/test/ruby_extensions_test.rb +0 -115
  99. data/vendor/plugins/guid/README.TXT +0 -29
  100. data/vendor/plugins/guid/init.rb +0 -30
  101. data/vendor/plugins/guid/lib/usesguid.rb +0 -37
  102. data/vendor/plugins/guid/lib/uuid22.rb +0 -43
  103. data/vendor/plugins/guid/lib/uuidtools.rb +0 -572
  104. data/vendor/plugins/responds_to_parent/MIT-LICENSE +0 -20
  105. data/vendor/plugins/responds_to_parent/README +0 -42
  106. data/vendor/plugins/responds_to_parent/Rakefile +0 -22
  107. data/vendor/plugins/responds_to_parent/init.rb +0 -1
  108. data/vendor/plugins/responds_to_parent/lib/responds_to_parent.rb +0 -46
  109. data/vendor/plugins/responds_to_parent/test/responds_to_parent_test.rb +0 -115
@@ -1,28 +0,0 @@
1
- module ActionController
2
- module Routing
3
-
4
- class << self
5
- # This holds the global list of valid controller paths
6
- attr_accessor :controller_paths
7
- end
8
-
9
- class ControllerComponent
10
- class << self
11
- protected
12
- def safe_load_paths #:nodoc:
13
- if defined?(RAILS_ROOT)
14
- paths = $LOAD_PATH.select do |base|
15
- base = File.expand_path(base)
16
- # Check that the path matches one of the allowed paths in controller_paths
17
- base.match(/^#{ActionController::Routing.controller_paths.map { |p| File.expand_path(p) } * '|'}/)
18
- end
19
- Engines.log.debug "Engines safe_load_paths: #{paths.inspect}"
20
- paths
21
- else
22
- $LOAD_PATH
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,327 +0,0 @@
1
- # The Engines testing extensions enable developers to load fixtures into specific
2
- # tables irrespective of the name of the fixtures file. This work is heavily based on
3
- # patches made by Duane Johnson (canadaduane), viewable at
4
- # http://dev.rubyonrails.org/ticket/1911
5
- #
6
- # Engine developers should supply fixture files in the <engine>/test/fixtures directory
7
- # as normal. Within their tests, they should load the fixtures using the 'fixture' command
8
- # (rather than the normal 'fixtures' command). For example:
9
- #
10
- # class UserTest < Test::Unit::TestCase
11
- # fixture :users, :table_name => LoginEngine.config(:user_table), :class_name => "User"
12
- #
13
- # ...
14
- #
15
- # This will ensure that the fixtures/users.yml file will get loaded into the correct
16
- # table, and will use the correct model object class.
17
-
18
-
19
-
20
- # A FixtureGroup is a set of fixtures identified by a name. Normally, this is the name of the
21
- # corresponding fixture filename. For example, when you declare the use of fixtures in a
22
- # TestUnit class, like so:
23
- # fixtures :users
24
- # you are creating a FixtureGroup whose name is 'users', and whose defaults are set such that the
25
- # +class_name+, +file_name+ and +table_name+ are guessed from the FixtureGroup's name.
26
- class FixtureGroup
27
- attr_accessor :table_name, :class_name, :connection
28
- attr_reader :group_name, :file_name
29
-
30
- def initialize(file_name, optional_names = {})
31
- self.file_name = file_name
32
- self.group_name = optional_names[:group_name] || file_name
33
- if optional_names[:table_name]
34
- self.table_name = optional_names[:table_name]
35
- self.class_name = optional_names[:class_name] || Inflector.classify(@table_name.to_s.gsub('.','_'))
36
- elsif optional_names[:class_name]
37
- self.class_name = optional_names[:class_name]
38
- if Object.const_defined?(@class_name)
39
- model_class = Object.const_get(@class_name)
40
- self.table_name = ActiveRecord::Base.table_name_prefix + model_class.table_name + ActiveRecord::Base.table_name_suffix
41
- end
42
- end
43
-
44
- # In case either :table_name or :class_name was not set:
45
- self.table_name ||= ActiveRecord::Base.table_name_prefix + @group_name.to_s + ActiveRecord::Base.table_name_suffix
46
- self.class_name ||= Inflector.classify(@table_name.to_s.gsub('.','_'))
47
- end
48
-
49
- def file_name=(name)
50
- @file_name = name.to_s
51
- end
52
-
53
- def group_name=(name)
54
- @group_name = name.to_sym
55
- end
56
-
57
- def class_file_name
58
- Inflector.underscore(@class_name)
59
- end
60
-
61
- # Instantiate an array of FixtureGroup objects from an array of strings (table_names)
62
- def self.array_from_names(names)
63
- names.collect { |n| FixtureGroup.new(n) }
64
- end
65
-
66
- def hash
67
- @group_name.hash
68
- end
69
-
70
- def eql?(other)
71
- @group_name.eql? other.group_name
72
- end
73
- end
74
-
75
- class Fixtures < YAML::Omap
76
-
77
- def self.instantiate_fixtures(object, fixture_group_name, fixtures, load_instances=true)
78
- old_logger_level = ActiveRecord::Base.logger.level
79
- ActiveRecord::Base.logger.level = Logger::ERROR
80
-
81
- # table_name.to_s.gsub('.','_') replaced by 'fixture_group_name'
82
- object.instance_variable_set "@#{fixture_group_name}", fixtures
83
- if load_instances
84
- ActiveRecord::Base.silence do
85
- fixtures.each do |name, fixture|
86
- begin
87
- if model = fixture.find
88
- object.instance_variable_set "@#{name}", model
89
- end
90
- rescue FixtureClassNotFound
91
- # Let's hope the developer has included it himself
92
- end
93
- end
94
- end
95
- end
96
-
97
- ActiveRecord::Base.logger.level = old_logger_level
98
- end
99
-
100
- # this doesn't really need to be overridden...
101
- def self.instantiate_all_loaded_fixtures(object, load_instances=true)
102
- all_loaded_fixtures.each do |fixture_group_name, fixtures|
103
- Fixtures.instantiate_fixtures(object, fixture_group_name, fixtures, load_instances)
104
- end
105
- end
106
-
107
- def self.create_fixtures(fixtures_directory, *fixture_groups)
108
- connection = block_given? ? yield : ActiveRecord::Base.connection
109
- fixture_groups.flatten!
110
-
111
- # Backwards compatibility: Allow an array of table names to be passed in, but just use them
112
- # to create an array of FixtureGroup objects
113
- if not fixture_groups.empty? and fixture_groups.first.is_a?(String)
114
- fixture_groups = FixtureGroup.array_from_names(fixture_groups)
115
- end
116
-
117
- ActiveRecord::Base.silence do
118
- fixtures_map = {}
119
- fixtures = fixture_groups.map do |group|
120
- fixtures_map[group.group_name] = Fixtures.new(connection, fixtures_directory, group)
121
- end
122
- # Make sure all refs to all_loaded_fixtures use group_name as hash index, not table_name
123
- all_loaded_fixtures.merge! fixtures_map
124
-
125
- connection.transaction do
126
- fixtures.reverse.each { |fixture| fixture.delete_existing_fixtures }
127
- fixtures.each { |fixture| fixture.insert_fixtures }
128
-
129
- # Cap primary key sequences to max(pk).
130
- if connection.respond_to?(:reset_pk_sequence!)
131
- fixture_groups.each do |fg|
132
- connection.reset_pk_sequence!(fg.table_name)
133
- end
134
- end
135
- end
136
-
137
- return fixtures.size > 1 ? fixtures : fixtures.first
138
- end
139
- end
140
-
141
-
142
- attr_accessor :connection, :fixtures_directory, :file_filter
143
- attr_accessor :fixture_group
144
-
145
- def initialize(connection, fixtures_directory, fixture_group, file_filter = DEFAULT_FILTER_RE)
146
- @connection, @fixtures_directory = connection, fixtures_directory
147
- @fixture_group = fixture_group
148
- @file_filter = file_filter
149
- read_fixture_files
150
- end
151
-
152
- def delete_existing_fixtures
153
- @connection.delete "DELETE FROM #{@fixture_group.table_name}", 'Fixture Delete'
154
- end
155
-
156
- def insert_fixtures
157
- values.each do |fixture|
158
- @connection.execute "INSERT INTO #{@fixture_group.table_name} (#{fixture.key_list}) VALUES (#{fixture.value_list})", 'Fixture Insert'
159
- end
160
- end
161
-
162
- private
163
- def read_fixture_files
164
- if File.file?(yaml_file_path)
165
- read_yaml_fixture_files
166
- elsif File.file?(csv_file_path)
167
- read_csv_fixture_files
168
- elsif File.file?(deprecated_yaml_file_path)
169
- raise Fixture::FormatError, ".yml extension required: rename #{deprecated_yaml_file_path} to #{yaml_file_path}"
170
- elsif File.directory?(single_file_fixtures_path)
171
- read_standard_fixture_files
172
- else
173
- raise Fixture::FixtureError, "Couldn't find a yaml, csv or standard file to load at #{@fixtures_directory} (#{@fixture_group.file_name})."
174
- end
175
- end
176
-
177
- def read_yaml_fixture_files
178
- # YAML fixtures
179
- begin
180
- if yaml = YAML::load(erb_render(IO.read(yaml_file_path)))
181
- yaml = yaml.value if yaml.respond_to?(:type_id) and yaml.respond_to?(:value)
182
- yaml.each do |name, data|
183
- self[name] = Fixture.new(data, fixture_group.class_name)
184
- end
185
- end
186
- rescue Exception=>boom
187
- raise Fixture::FormatError, "a YAML error occured parsing #{yaml_file_path}. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html\nThe exact error was:\n #{boom.class}: #{boom}"
188
- end
189
- end
190
-
191
- def read_csv_fixture_files
192
- # CSV fixtures
193
- reader = CSV::Reader.create(erb_render(IO.read(csv_file_path)))
194
- header = reader.shift
195
- i = 0
196
- reader.each do |row|
197
- data = {}
198
- row.each_with_index { |cell, j| data[header[j].to_s.strip] = cell.to_s.strip }
199
- self["#{@fixture_group.class_file_name}_#{i+=1}"]= Fixture.new(data, @fixture_group.class_name)
200
- end
201
- end
202
-
203
- def read_standard_fixture_files
204
- # Standard fixtures
205
- path = File.join(@fixtures_directory, @fixture_group.file_name)
206
- Dir.entries(path).each do |file|
207
- path = File.join(@fixtures_directory, @fixture_group.file_name, file)
208
- if File.file?(path) and file !~ @file_filter
209
- self[file] = Fixture.new(path, @fixture_group.class_name)
210
- end
211
- end
212
- end
213
-
214
- def yaml_file_path
215
- fixture_path_with_extension ".yml"
216
- end
217
-
218
- def deprecated_yaml_file_path
219
- fixture_path_with_extension ".yaml"
220
- end
221
-
222
- def csv_file_path
223
- fixture_path_with_extension ".csv"
224
- end
225
-
226
- def single_file_fixtures_path
227
- fixture_path_with_extension ""
228
- end
229
-
230
- def fixture_path_with_extension(ext)
231
- File.join(@fixtures_directory, @fixture_group.file_name + ext)
232
- end
233
-
234
- def erb_render(fixture_content)
235
- ERB.new(fixture_content).result
236
- end
237
-
238
- end
239
-
240
- module Test #:nodoc:
241
- module Unit #:nodoc:
242
- class TestCase #:nodoc:
243
- cattr_accessor :fixtures_directory
244
- class_inheritable_accessor :fixture_groups
245
- class_inheritable_accessor :fixture_table_names
246
- class_inheritable_accessor :use_transactional_fixtures
247
- class_inheritable_accessor :use_instantiated_fixtures # true, false, or :no_instances
248
- class_inheritable_accessor :pre_loaded_fixtures
249
-
250
- self.fixture_groups = []
251
- self.use_transactional_fixtures = false
252
- self.use_instantiated_fixtures = true
253
- self.pre_loaded_fixtures = false
254
-
255
- @@already_loaded_fixtures = {}
256
-
257
- # Backwards compatibility
258
- def self.fixture_path=(path); self.fixtures_directory = path; end
259
- def self.fixture_path; self.fixtures_directory; end
260
- def fixture_group_names; fixture_groups.collect { |g| g.group_name }; end
261
- def fixture_table_names; fixture_group_names; end
262
-
263
- def self.fixture(file_name, options = {})
264
- self.fixture_groups |= [FixtureGroup.new(file_name, options)]
265
- require_fixture_classes
266
- setup_fixture_accessors
267
- end
268
-
269
- def self.fixtures(*file_names)
270
- self.fixture_groups |= FixtureGroup.array_from_names(file_names.flatten)
271
- require_fixture_classes
272
- setup_fixture_accessors
273
- end
274
-
275
- def self.require_fixture_classes(fixture_groups_override = nil)
276
- (fixture_groups_override || fixture_groups).each do |group|
277
- begin
278
- require group.class_file_name
279
- rescue LoadError
280
- # Let's hope the developer has included it himself
281
- end
282
- end
283
- end
284
-
285
- def self.setup_fixture_accessors(fixture_groups_override=nil)
286
- (fixture_groups_override || fixture_groups).each do |group|
287
- define_method(group.group_name) do |fixture, *optionals|
288
- force_reload = optionals.shift
289
- @fixture_cache[group.group_name] ||= Hash.new
290
- @fixture_cache[group.group_name][fixture] = nil if force_reload
291
- @fixture_cache[group.group_name][fixture] ||= @loaded_fixtures[group.group_name][fixture.to_s].find
292
- end
293
- end
294
- end
295
-
296
- private
297
- def load_fixtures
298
- @loaded_fixtures = {}
299
- fixtures = Fixtures.create_fixtures(fixtures_directory, fixture_groups)
300
- unless fixtures.nil?
301
- if fixtures.instance_of?(Fixtures)
302
- @loaded_fixtures[fixtures.fixture_group.group_name] = fixtures
303
- else
304
- fixtures.each { |f| @loaded_fixtures[f.fixture_group.group_name] = f }
305
- end
306
- end
307
- end
308
-
309
- def instantiate_fixtures
310
- if pre_loaded_fixtures
311
- raise RuntimeError, 'Load fixtures before instantiating them.' if Fixtures.all_loaded_fixtures.empty?
312
- unless @@required_fixture_classes
313
- groups = Fixtures.all_loaded_fixtures.values.collect { |f| f.group_name }
314
- self.class.require_fixture_classes groups
315
- @@required_fixture_classes = true
316
- end
317
- Fixtures.instantiate_all_loaded_fixtures(self, load_instances?)
318
- else
319
- raise RuntimeError, 'Load fixtures before instantiating them.' if @loaded_fixtures.nil?
320
- @loaded_fixtures.each do |fixture_group_name, fixtures|
321
- Fixtures.instantiate_fixtures(self, fixture_group_name, fixtures, load_instances?)
322
- end
323
- end
324
- end
325
- end
326
- end
327
- end
@@ -1,7 +0,0 @@
1
- # Old-style engines rake tasks.
2
- # NOTE: THESE ARE DEPRICATED! PLEASE USE THE NEW STYLE!
3
-
4
- task :engine_info => "engines:info"
5
- task :engine_migrate => "db:migrate:engines"
6
- task :enginedoc => "doc:engines"
7
- task :load_plugin_fixtures => "db:fixtures:engines:load"
@@ -1,9 +0,0 @@
1
- ENV["RAILS_ENV"] = "test"
2
- require File.expand_path(File.dirname(__FILE__) + '/../../../../config/environment')
3
- require 'test_help'
4
-
5
- class ActionViewExtensionsTest < Test::Unit::TestCase
6
- def test_stylesheet_path
7
- assert true
8
- end
9
- end
@@ -1,115 +0,0 @@
1
- ENV["RAILS_ENV"] = "test"
2
- require File.expand_path(File.dirname(__FILE__) + '/../../../../config/environment')
3
- require 'test_help'
4
-
5
- class RubyExtensionsTest < Test::Unit::TestCase
6
-
7
- def setup
8
- # create the module to be used for config testing
9
- eval "module TestModule end"
10
- end
11
-
12
- def teardown
13
- # remove the TestModule constant from our scope
14
- self.class.class_eval { remove_const :TestModule }
15
- end
16
-
17
-
18
- #
19
- # Module.config
20
- #
21
-
22
- def test_config_no_arguments
23
- assert_raise(RuntimeError) { TestModule.config }
24
- end
25
-
26
- def test_config_array_arguments
27
- TestModule.config :monkey, 123
28
- assert_equal(123, TestModule.config(:monkey))
29
- end
30
-
31
- def test_config_hash_arguments
32
- TestModule.config :monkey => 123, :donkey => 456
33
- assert_equal(123, TestModule.config(:monkey))
34
- assert_equal(456, TestModule.config(:donkey))
35
- end
36
-
37
- def test_config_can_store_hash
38
- TestModule.config :hash, :key1 => 'val1', :key2 => 'val2'
39
- assert_equal({:key1 => 'val1', :key2 => 'val2'}, TestModule.config(:hash))
40
- end
41
-
42
- def test_config_cant_overwrite_existing_config_values
43
- TestModule.config :monkey, 123
44
- assert_equal(123, TestModule.config(:monkey))
45
- TestModule.config :monkey, 456
46
- assert_equal(123, TestModule.config(:monkey))
47
-
48
- TestModule.config :monkey => 456
49
- assert_equal(123, TestModule.config(:monkey))
50
-
51
- # in this case, the resulting Hash only has {:baboon => "goodbye!"} - that's Ruby, users beware.
52
- TestModule.config :baboon => "hello", :baboon => "goodbye!"
53
- assert_equal("goodbye!", TestModule.config(:baboon))
54
- end
55
-
56
- def test_config_force_new_value
57
- TestModule.config :monkey, 123
58
- TestModule.config :man, 321
59
- assert_equal(123, TestModule.config(:monkey))
60
- assert_equal(321, TestModule.config(:man))
61
- TestModule.config :monkey, 456, :force
62
- assert_equal(456, TestModule.config(:monkey))
63
- TestModule.config :monkey => 456, :man => 654, :force => true
64
- assert_equal(456, TestModule.config(:monkey))
65
- assert_equal(654, TestModule.config(:man))
66
- TestModule.config :monkey => 789, :man => 987, :force => false
67
- assert_equal(456, TestModule.config(:monkey))
68
- assert_equal(654, TestModule.config(:man))
69
-
70
- TestModule.config :hash, :key1 => 'val1', :key2 => 'val2'
71
- assert_equal({:key1 => 'val1', :key2 => 'val2'}, TestModule.config(:hash))
72
- TestModule.config :hash => {:key1 => 'val3', :key2 => 'val4'}, :force => true
73
- assert_equal({:key1 => 'val3', :key2 => 'val4'}, TestModule.config(:hash))
74
- end
75
-
76
- # this test is somewhat redundant, but it might be an idea to havbe it explictly anyway
77
- def test_config_get_values
78
- TestModule.config :monkey, 123
79
- assert_equal(123, TestModule.config(:monkey))
80
- end
81
-
82
- def test_config_get_multiple_values
83
- TestModule.config :monkey, 123
84
- TestModule.config :donkey, 456
85
- assert_equal([123, 456], TestModule.config([:monkey, :donkey]))
86
- end
87
-
88
-
89
- #
90
- # Module.default_constant
91
- #
92
-
93
- def test_default_constant_set
94
- TestModule.default_constant :Monkey, 123
95
- assert_equal(123, TestModule::Monkey)
96
- TestModule.default_constant "Hello", 456
97
- assert_equal(456, TestModule::Hello)
98
- end
99
-
100
- def test_default_constant_cannot_set_again
101
- TestModule.default_constant :Monkey, 789
102
- assert_equal(789, TestModule::Monkey)
103
- TestModule.default_constant :Monkey, 456
104
- assert_equal(789, TestModule::Monkey)
105
- end
106
-
107
- def test_default_constant_bad_arguments
108
- # constant names must be Captialized
109
- assert_raise(NameError) { TestModule.default_constant :lowercase_name, 123 }
110
-
111
- # constant names should be given as Strings or Symbols
112
- assert_raise(RuntimeError) { TestModule.default_constant 123, 456 }
113
- assert_raise(RuntimeError) { TestModule.default_constant Object.new, 456 }
114
- end
115
- end
@@ -1,29 +0,0 @@
1
- # This plugin for ActiveRecord makes the "ID" field into a URL-safe GUID
2
- # It is a mashup by Andy Singleton <andy@assembla.com> that includes
3
- # * the UUID class from Bob Aman.
4
- # * the plugin skeleton from Demetrius Nunes
5
- # * the 22 character URL-safe format from Andy Singleton
6
- # You can get standard 36 char UUID formats instead
7
- # TODO: Auto-detect a character ID field and use a GUID in this case (DRY principle)
8
- #
9
- # This library is free software; you can redistribute it and/or modify it
10
- # under the terms of the MIT license.
11
- #
12
- # TO USE
13
- # Install as a plugin in the rails directory vendor/plugin/guid
14
- # define ID as char(22)
15
- # call "usesguid" in ActiveRecord class declaration, like
16
- class Mymodel < ActiveRecord::Base
17
- usesguid
18
-
19
- # if your ID field is not called "ID", call "usesguid :column =>'IdColumnName' "
20
-
21
- # if you create your tables with migrations, you need to bypass the rails default primary key index. Do this:
22
-
23
- create_table :mytable, :id => false do |t|
24
- t.column :id, :string, :limit => 22
25
- ... more fields
26
- end
27
-
28
- execute "ALTER TABLE mytable ADD PRIMARY KEY (id)"
29
-
@@ -1,30 +0,0 @@
1
- # Copyright (c) 2005 Assembla, Inc.
2
- #
3
- # This plugin for ActiveRecord makes the "ID" field into a URL-safe GUID
4
- # It is a mashup by Andy Singleton <andy@assembla.com> that includes
5
- # * the UUID class from Bob Aman.
6
- # * the plugin skeleton from Demetrius Nunes
7
- # * the 22 character URL-safe format from Andy Singleton
8
- # You can get standard 36 char UUID formats instead
9
- # TODO: Auto-detect a character ID field and use a GUID in this case (DRY principle)
10
- #
11
- # This library is free software; you can redistribute it and/or modify it
12
- # under the terms of the MIT license.
13
- #
14
- # TO USE
15
- # Install as a plugin in the rails directory vendor/plugin/guid
16
- # define ID as char(22)
17
- # call "usesguid" in ActiveRecord class declaration, like
18
- # class Mymodel < ActiveRecord::Base
19
- # usesguid
20
- #
21
- # if your ID field is not called "ID", call "usesguid :column =>'IdColumnName' "
22
-
23
- # if you create your tables with migrations, you need to bypass the rails default primary key index. Do this:
24
- # create_table :mytable, :id => false do |t|
25
- # t.column :id, :string, :limit => 22
26
- # ... more fields
27
- # end
28
- # execute "ALTER TABLE mytable ADD PRIMARY KEY (id)"
29
-
30
- require 'usesguid'
@@ -1,37 +0,0 @@
1
- # from Demetrio Nunes
2
- # Modified by Andy Singleton to use different GUID generator
3
- #
4
- # MIT License
5
-
6
- require 'uuid22'
7
-
8
- module ActiveRecord
9
- module Usesguid #:nodoc:
10
-
11
- def self.append_features(base)
12
- super
13
- base.extend(ClassMethods)
14
- end
15
-
16
-
17
- module ClassMethods
18
-
19
- def usesguid(options = {})
20
-
21
- class_eval do
22
- set_primary_key options[:column] if options[:column]
23
-
24
- def after_initialize
25
- self.id ||= UUID.timestamp_create().to_s22
26
- end
27
- end
28
-
29
- end
30
-
31
- end
32
- end
33
- end
34
-
35
- ActiveRecord::Base.class_eval do
36
- include ActiveRecord::Usesguid
37
- end
@@ -1,43 +0,0 @@
1
- # Copyright (c) 2005 Assembla, Inc.
2
- # MIT License
3
-
4
- require 'uuidtools'
5
-
6
- class UUID
7
-
8
- # Make an array of 64 URL-safe characters
9
- @@chars64=('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a + ['-','_']
10
- #return a 22 byte URL-safe string, encoded six bits at a time using 64 characters
11
- def to_s22
12
- integer=self.to_i
13
- rval=''
14
- 22.times do
15
- c=(integer & 0x3F)
16
- rval+=@@chars64[c]
17
- integer =integer >> 6
18
- end
19
- return rval.reverse
20
- end
21
- # Create a new UUID from a 22char string
22
- def self.parse22(s)
23
- # get the integer representation
24
- integer=0
25
- s.each_byte {|c|
26
- integer = integer << 6
27
- pos=@@chars64.index(c.chr)
28
- integer+=pos
29
- }
30
-
31
- time_low = (integer >> 96) & 0xFFFFFFFF
32
- time_mid = (integer >> 80) & 0xFFFF
33
- time_hi_and_version = (integer >> 64) & 0xFFFF
34
- clock_seq_hi_and_reserved = (integer >> 56) & 0xFF
35
- clock_seq_low = (integer >> 48) & 0xFF
36
- nodes = []
37
- for i in 0..5 do
38
- nodes << ((integer >> (40 - (i * 8))) & 0xFF)
39
- end
40
- return new(time_low, time_mid, time_hi_and_version,
41
- clock_seq_hi_and_reserved, clock_seq_low, nodes)
42
- end
43
- end