muck-engine 0.4.26 → 0.4.27

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -57,6 +57,7 @@ begin
57
57
  gemspec.add_dependency "validation_reflection"
58
58
  gemspec.add_dependency "will_paginate"
59
59
  gemspec.add_dependency "git"
60
+ gemspec.add_dependency "overlord"
60
61
  gemspec.add_development_dependency "shoulda"
61
62
  end
62
63
  Jeweler::RubyforgeTasks.new do |rubyforge|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.26
1
+ 0.4.27
@@ -9,53 +9,5 @@
9
9
  #
10
10
 
11
11
  class Country < ActiveRecord::Base
12
-
13
- has_many :states
14
-
15
- named_scope :by_name, :order => "name ASC"
16
-
17
- def self.us
18
- self.find_by_abbreviation('US')
19
- end
20
-
21
- def self.uk_country?(country_id)
22
- unless defined?(@@uk_country_ids)
23
- uk_countries = Country.find(:all, :conditions => ["abbreviation in (?)", ['ENG', 'IE', 'WAL', 'SCT']])
24
- @@uk_country_ids = uk_countries.map(&:id)
25
- end
26
- @@uk_country_ids.include?(country_id.to_i)
27
- end
28
-
29
- def self.canada?(country_id)
30
- @@canada_id ||= Country.find_by_abbreviation('CA').id
31
- @@canada_id == country_id.to_i
32
- end
33
-
34
- # Note that the strings from here are also hard coded into application.js
35
- def self.build_state_prompts(country_id, any = false)
36
- if uk_country?(country_id)
37
- label = 'Choose County'
38
- if any
39
- prompt = 'Any County (or unknown)'
40
- else
41
- prompt = 'Please select a county'
42
- end
43
- elsif canada?(country_id)
44
- label = 'Choose Province'
45
- if any
46
- prompt = 'Any Province (or unknown)'
47
- else
48
- prompt = 'Please select a Province'
49
- end
50
- else
51
- label = 'Choose State'
52
- if any
53
- prompt = 'Any State (or unknown)'
54
- else
55
- prompt = 'Please select a state'
56
- end
57
- end
58
- [label, prompt]
59
- end
60
-
12
+ acts_as_muck_country
61
13
  end
@@ -11,26 +11,5 @@
11
11
  #
12
12
 
13
13
  class Language < ActiveRecord::Base
14
-
15
- @@locale_ids = nil
16
-
17
- def self.locale_id
18
- cache_locale_ids
19
- @@locale_ids[I18n.locale]
20
- end
21
-
22
- def self.supported_locale? locale
23
- cache_locale_ids
24
- @@locale_ids[locale.to_sym] != nil
25
- end
26
-
27
- private
28
-
29
- def self.cache_locale_ids
30
- if !@@locale_ids
31
- languages = Language.find(:all, :select => 'id, locale', :conditions => ['languages.supported = ?', true])
32
- @@locale_ids = Hash[*languages.collect {|v|[v.locale[0..1].to_sym, v.id]}.flatten]
33
- end
34
- end
35
-
14
+ acts_as_muck_language
36
15
  end
data/app/models/state.rb CHANGED
@@ -9,7 +9,5 @@
9
9
  #
10
10
 
11
11
  class State < ActiveRecord::Base
12
- belongs_to :country
13
- named_scope :by_name, :order => "name ASC"
14
-
12
+ acts_as_muck_state
15
13
  end
@@ -0,0 +1,84 @@
1
+ module ActiveRecord
2
+ module Acts #:nodoc:
3
+ module MuckCountry #:nodoc:
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def acts_as_muck_country
10
+ has_many :states
11
+ named_scope :by_name, :order => "name ASC"
12
+
13
+ include ActiveRecord::Acts::MuckCountry::InstanceMethods
14
+ extend ActiveRecord::Acts::MuckCountry::SingletonMethods
15
+
16
+ end
17
+ end
18
+
19
+ # class methods
20
+ module SingletonMethods
21
+ def us
22
+ self.find_by_abbreviation('US')
23
+ end
24
+
25
+ def uk_country?(country, refresh_ids = false)
26
+ if refresh_ids || !defined?(@@uk_country_ids)
27
+ uk_countries = Country.find(:all, :conditions => ["abbreviation in (?)", ['ENG', 'IE', 'WAL', 'SCT']])
28
+ @@uk_country_ids = uk_countries.map(&:id)
29
+ end
30
+ @@uk_country_ids.include?(get_country_id(country))
31
+ end
32
+
33
+ def canada?(country, refresh_ids = false)
34
+ @@canada_id = nil if refresh_ids
35
+ @@canada_id ||= Country.find_by_abbreviation('CA').id
36
+ @@canada_id == get_country_id(country)
37
+ end
38
+
39
+ # Note that the strings from here are also hard coded into application.js
40
+ def build_state_prompts(country_id, any = false)
41
+ if uk_country?(country_id)
42
+ label = 'Choose County'
43
+ if any
44
+ prompt = 'Any County (or unknown)'
45
+ else
46
+ prompt = 'Please select a county'
47
+ end
48
+ elsif canada?(country_id)
49
+ label = 'Choose Province'
50
+ if any
51
+ prompt = 'Any Province (or unknown)'
52
+ else
53
+ prompt = 'Please select a province'
54
+ end
55
+ else
56
+ label = 'Choose State'
57
+ if any
58
+ prompt = 'Any State (or unknown)'
59
+ else
60
+ prompt = 'Please select a state'
61
+ end
62
+ end
63
+ [label, prompt]
64
+ end
65
+
66
+ private
67
+
68
+ def get_country_id(country)
69
+ if country.is_a?(Country)
70
+ country.id
71
+ else
72
+ country.to_i
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ # All the methods available to a record that has had <tt>acts_as_muck_invite</tt> specified.
79
+ module InstanceMethods
80
+ end
81
+
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,50 @@
1
+ module ActiveRecord
2
+ module Acts #:nodoc:
3
+ module MuckLanguage #:nodoc:
4
+
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def acts_as_muck_language
11
+ include ActiveRecord::Acts::MuckLanguage::InstanceMethods
12
+ extend ActiveRecord::Acts::MuckLanguage::SingletonMethods
13
+ end
14
+ end
15
+
16
+ # class methods
17
+ module SingletonMethods
18
+ def locale_id(refresh_ids = false)
19
+ cache_locale_ids
20
+ @@locale_ids[I18n.locale]
21
+ end
22
+
23
+ def supported_locale?(locale, refresh_ids = false)
24
+ cache_locale_ids
25
+ @@locale_ids[locale.to_sym] != nil
26
+ end
27
+
28
+ private
29
+
30
+ def cache_locale_ids(refresh_ids = false)
31
+ if refresh_ids || !defined?(@@locale_ids)
32
+ languages = Language.find(:all, :select => 'id, locale', :conditions => ['languages.supported = ?', true])
33
+ @@locale_ids = Hash[*languages.collect {|v|[v.locale[0..1].to_sym, v.id]}.flatten]
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ # All the methods available to a record that has had <tt>acts_as_muck_invite</tt> specified.
40
+ module InstanceMethods
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+
47
+
48
+
49
+
50
+
@@ -0,0 +1,30 @@
1
+ module ActiveRecord
2
+ module Acts #:nodoc:
3
+ module MuckState #:nodoc:
4
+
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def acts_as_muck_state
11
+ belongs_to :country
12
+ named_scope :by_name, :order => "name ASC"
13
+
14
+ include ActiveRecord::Acts::MuckState::InstanceMethods
15
+ extend ActiveRecord::Acts::MuckState::SingletonMethods
16
+
17
+ end
18
+ end
19
+
20
+ # class methods
21
+ module SingletonMethods
22
+ end
23
+
24
+ # All the methods available to a record that has had <tt>acts_as_muck_invite</tt> specified.
25
+ module InstanceMethods
26
+ end
27
+
28
+ end
29
+ end
30
+ end
data/lib/muck_engine.rb CHANGED
@@ -3,6 +3,9 @@ require 'muck_engine/flash_errors'
3
3
  ActionController::Base.send :include, ActionController::MuckApplication
4
4
  ActionController::Base.send :include, MuckEngine::FlashErrors
5
5
  ActiveRecord::Base.send :include, ActiveRecord::MuckModel
6
+ ActiveRecord::Base.class_eval { include ActiveRecord::Acts::MuckLanguage }
7
+ ActiveRecord::Base.class_eval { include ActiveRecord::Acts::MuckCountry }
8
+ ActiveRecord::Base.class_eval { include ActiveRecord::Acts::MuckState }
6
9
  ActionMailer::Base.send :include, ActionMailer::MuckMailer
7
10
  ActionController::Base.send :helper, MuckEngineHelper
8
11
  ActionController::Base.send :helper, MuckAdminHelper
@@ -2,6 +2,8 @@ require 'rake'
2
2
  require 'rake/tasklib'
3
3
  require 'fileutils'
4
4
  require 'jcode'
5
+ require 'rubygems'
6
+
5
7
  begin
6
8
  require 'git'
7
9
  rescue LoadError
@@ -163,22 +165,22 @@ class MuckEngine
163
165
  version = IO.read(version_file).strip
164
166
  environment = IO.read(gem_file)
165
167
 
166
- search = Regexp.new(/\:require_as\s*=>\s*['"]#{gem_lib}['"],\s*['"][ <>=~]*\d+\.\d+\.\d+['"]/)
167
- failure = environment.gsub!(search, "'>=#{version}', :require_as => '#{gem_lib}'").nil?
168
+ search = Regexp.new(/\:require\s*=>\s*['"]#{gem_lib}['"],\s*['"][ <>=~]*\d+\.\d+\.\d+['"]/)
169
+ failure = environment.gsub!(search, "'#{version}', :require => '#{gem_lib}'").nil?
168
170
 
169
171
  if failure
170
172
  search = Regexp.new(/gem\s*['"]#{gem_name}['"],\s*['"][ <>=~]*\d+\.\d+\.\d+['"]/)
171
- failure = environment.gsub!(search, "gem '#{gem_name}', '>=#{version}'").nil?
173
+ failure = environment.gsub!(search, "gem '#{gem_name}', '#{version}'").nil?
172
174
  end
173
175
 
174
176
  if failure
175
- search = Regexp.new(/gem\s*['"]#{gem_name}['"],\s*\:require_as\s*=>\s*['"]#{gem_lib}['"]/)
176
- failure = environment.gsub!(search, "gem '#{gem_name}', '>=#{version}', :require_as => '#{gem_lib}'").nil?
177
+ search = Regexp.new(/gem\s*['"]#{gem_name}['"],\s*\:require\s*=>\s*['"]#{gem_lib}['"]/)
178
+ failure = environment.gsub!(search, "gem '#{gem_name}', '#{version}', :require => '#{gem_lib}'").nil?
177
179
  end
178
180
 
179
181
  if failure
180
182
  search = Regexp.new(/gem\s*['"]#{gem_name}['"]/)
181
- failure = environment.gsub!(search, "gem '#{gem_name}', '>=#{version}'").nil?
183
+ failure = environment.gsub!(search, "gem '#{gem_name}', '#{version}'").nil?
182
184
  end
183
185
 
184
186
  if failure
@@ -188,6 +190,44 @@ class MuckEngine
188
190
  File.open(gem_file, 'w') { |f| f.write(environment) }
189
191
  end
190
192
 
193
+ # Rewrite the Gemfile with the latest gem versions installed on the local machine.
194
+ def update_gem_file
195
+ gemfile = File.join(RAILS_ROOT, 'Gemfile')
196
+ contents = IO.read(gemfile)
197
+ gems = contents.scan(/gem\s*['"]([-_\d\w]+)['"],\s*(['"][~><>=\d\.]+['"])?\s*(\:require\s*=>\s*['"]\w+['"])?/)
198
+ gems.each do |g|
199
+ success = false
200
+ search = "gem #{g[0]}"
201
+ search << ", #{g[1]}" if g[1] # add on version if it was present
202
+ search << ", #{g[2]}" if g[2] # add on require if it was present
203
+ new_version = get_gem_version(g[0])
204
+ if new_version
205
+ replace = "gem #{g[0]}, '#{new_version}'"
206
+ replace << ", #{g[2]}" if g[2] # add on require if it was present
207
+ success = !contents.gsub!(search, replace)
208
+ end
209
+ if !success
210
+ puts "Failed to update version for #{g[0]}"
211
+ end
212
+ end
213
+ File.open(gemfile, 'w') { |f| f.write(contents) }
214
+ end
215
+
216
+ # Get the latest gem version
217
+ def get_gem_version(gem_name)
218
+ @si ||= Gem::SourceIndex.from_installed_gems
219
+ gems = @si.find_name(gem_name)
220
+ newest_gem = gems[0]
221
+ if newest_gem
222
+ gems.each do |gem|
223
+ newest_gem = gem if gem.version > newest_gem.version
224
+ end
225
+ newest_gem.version.version
226
+ else
227
+ #puts "Failed to find #{gem_name} in index"
228
+ end
229
+ end
230
+
191
231
  def git_commit(path, message)
192
232
  puts "Commiting #{BLUE}#{File.basename(path)}#{INVERT}"
193
233
  repo = Git.open("#{path}")
@@ -349,13 +389,18 @@ class MuckEngine
349
389
  end
350
390
  end
351
391
 
352
- desc "Write muck gem versions into application's gem file"
353
- task :bundle do
392
+ desc "Write muck gem versions into application's 'Gemfile'"
393
+ task :vers do
354
394
  muck_gem_names.each do |gem_name|
355
395
  write_new_gem_version_in_bundle("#{projects_path}", gem_name)
356
396
  end
357
397
  end
358
398
 
399
+ desc "Write gem versions (for all gems) into application's 'Gemfile'. Be sure to test with the updated gems and check the new versions."
400
+ task :vers_all => :environment do
401
+ update_gem_file
402
+ end
403
+
359
404
  desc 'Translate app into all languages supported by Google'
360
405
  task :translate_app => :environment do
361
406
  puts 'translating app'
@@ -55,6 +55,15 @@ Factory.define :language do |f|
55
55
  f.muck_raker_supported true
56
56
  end
57
57
 
58
+ # This is used for tests within muck-engine. The language
59
+ # model is modified by migrations in other gems to include 'muck_raker_supported'
60
+ Factory.define :unmodified_language, :class => Language do |f|
61
+ f.name { Factory.next(:name) }
62
+ f.english_name { Factory.next(:name) }
63
+ f.locale { Factory.next(:locale) }
64
+ f.supported true
65
+ end
66
+
58
67
  Factory.define :user do |f|
59
68
  f.login { Factory.next(:login) }
60
69
  f.email { Factory.next(:email) }
data/muck-engine.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{muck-engine}
8
- s.version = "0.4.26"
8
+ s.version = "0.4.27"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin Ball", "Joel Duffin"]
12
- s.date = %q{2010-05-14}
12
+ s.date = %q{2010-05-31}
13
13
  s.description = %q{The base engine for the muck system. Contains common tables, custom for, css and javascript.}
14
14
  s.email = %q{justin@tatemae.com}
15
15
  s.extra_rdoc_files = [
@@ -72,6 +72,9 @@ Gem::Specification.new do |s|
72
72
  "install.rb",
73
73
  "lib/action_controller/muck_application.rb",
74
74
  "lib/action_mailer/muck_mailer.rb",
75
+ "lib/active_record/acts/muck_country.rb",
76
+ "lib/active_record/acts/muck_language.rb",
77
+ "lib/active_record/acts/muck_state.rb",
75
78
  "lib/active_record/muck_model.rb",
76
79
  "lib/muck_engine.rb",
77
80
  "lib/muck_engine/flash_errors.rb",
@@ -667,6 +670,7 @@ Gem::Specification.new do |s|
667
670
  "tasks/rails.rake",
668
671
  "test/rails_root/.gitignore",
669
672
  "test/rails_root/.rake_tasks",
673
+ "test/rails_root/Gemfile",
670
674
  "test/rails_root/Rakefile",
671
675
  "test/rails_root/app/controllers/admin/default_controller.rb",
672
676
  "test/rails_root/app/controllers/application_controller.rb",
@@ -690,6 +694,7 @@ Gem::Specification.new do |s|
690
694
  "test/rails_root/config/initializers/mime_types.rb",
691
695
  "test/rails_root/config/initializers/requires.rb",
692
696
  "test/rails_root/config/initializers/session_store.rb",
697
+ "test/rails_root/config/preinitializer.rb",
693
698
  "test/rails_root/config/routes.rb",
694
699
  "test/rails_root/db/.keep",
695
700
  "test/rails_root/db/migrate/20090320174818_create_muck_permissions_and_roles.rb",
@@ -1274,13 +1279,17 @@ Gem::Specification.new do |s|
1274
1279
  "test/rails_root/test/functional/.keep",
1275
1280
  "test/rails_root/test/functional/admin/default_controller_test.rb",
1276
1281
  "test/rails_root/test/functional/default_controller_test.rb",
1282
+ "test/rails_root/test/functional/helper_controller_test.rb",
1277
1283
  "test/rails_root/test/integration/.keep",
1278
1284
  "test/rails_root/test/mocks/development/.keep",
1279
1285
  "test/rails_root/test/mocks/test/.keep",
1280
1286
  "test/rails_root/test/test_helper.rb",
1281
1287
  "test/rails_root/test/unit/.keep",
1282
1288
  "test/rails_root/test/unit/basic_mailer_test.rb",
1289
+ "test/rails_root/test/unit/country_test.rb",
1290
+ "test/rails_root/test/unit/language_test.rb",
1283
1291
  "test/rails_root/test/unit/muck_engine_helper_test.rb",
1292
+ "test/rails_root/test/unit/state_test.rb",
1284
1293
  "test/rails_root/vendor/plugins/ssl_requirement/README",
1285
1294
  "test/rails_root/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb",
1286
1295
  "test/rails_root/vendor/plugins/ssl_requirement/test/ssl_requirement_test.rb",
@@ -1290,7 +1299,7 @@ Gem::Specification.new do |s|
1290
1299
  s.rdoc_options = ["--charset=UTF-8"]
1291
1300
  s.require_paths = ["lib"]
1292
1301
  s.rubyforge_project = %q{muck-engine}
1293
- s.rubygems_version = %q{1.3.6}
1302
+ s.rubygems_version = %q{1.3.7}
1294
1303
  s.summary = %q{The base engine for the muck system.}
1295
1304
  s.test_files = [
1296
1305
  "test/rails_root/app/controllers/admin/default_controller.rb",
@@ -1308,6 +1317,7 @@ Gem::Specification.new do |s|
1308
1317
  "test/rails_root/config/initializers/mime_types.rb",
1309
1318
  "test/rails_root/config/initializers/requires.rb",
1310
1319
  "test/rails_root/config/initializers/session_store.rb",
1320
+ "test/rails_root/config/preinitializer.rb",
1311
1321
  "test/rails_root/config/routes.rb",
1312
1322
  "test/rails_root/db/migrate/20090320174818_create_muck_permissions_and_roles.rb",
1313
1323
  "test/rails_root/db/migrate/20090402234137_create_languages.rb",
@@ -1320,9 +1330,13 @@ Gem::Specification.new do |s|
1320
1330
  "test/rails_root/script/create_project.rb",
1321
1331
  "test/rails_root/test/functional/admin/default_controller_test.rb",
1322
1332
  "test/rails_root/test/functional/default_controller_test.rb",
1333
+ "test/rails_root/test/functional/helper_controller_test.rb",
1323
1334
  "test/rails_root/test/test_helper.rb",
1324
1335
  "test/rails_root/test/unit/basic_mailer_test.rb",
1336
+ "test/rails_root/test/unit/country_test.rb",
1337
+ "test/rails_root/test/unit/language_test.rb",
1325
1338
  "test/rails_root/test/unit/muck_engine_helper_test.rb",
1339
+ "test/rails_root/test/unit/state_test.rb",
1326
1340
  "test/rails_root/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb",
1327
1341
  "test/rails_root/vendor/plugins/ssl_requirement/test/ssl_requirement_test.rb"
1328
1342
  ]
@@ -1331,21 +1345,24 @@ Gem::Specification.new do |s|
1331
1345
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
1332
1346
  s.specification_version = 3
1333
1347
 
1334
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
1348
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
1335
1349
  s.add_runtime_dependency(%q<validation_reflection>, [">= 0"])
1336
1350
  s.add_runtime_dependency(%q<will_paginate>, [">= 0"])
1337
1351
  s.add_runtime_dependency(%q<git>, [">= 0"])
1352
+ s.add_runtime_dependency(%q<overlord>, [">= 0"])
1338
1353
  s.add_development_dependency(%q<shoulda>, [">= 0"])
1339
1354
  else
1340
1355
  s.add_dependency(%q<validation_reflection>, [">= 0"])
1341
1356
  s.add_dependency(%q<will_paginate>, [">= 0"])
1342
1357
  s.add_dependency(%q<git>, [">= 0"])
1358
+ s.add_dependency(%q<overlord>, [">= 0"])
1343
1359
  s.add_dependency(%q<shoulda>, [">= 0"])
1344
1360
  end
1345
1361
  else
1346
1362
  s.add_dependency(%q<validation_reflection>, [">= 0"])
1347
1363
  s.add_dependency(%q<will_paginate>, [">= 0"])
1348
1364
  s.add_dependency(%q<git>, [">= 0"])
1365
+ s.add_dependency(%q<overlord>, [">= 0"])
1349
1366
  s.add_dependency(%q<shoulda>, [">= 0"])
1350
1367
  end
1351
1368
  end
@@ -0,0 +1,30 @@
1
+ source :gemcutter
2
+
3
+ gem "rails", "2.3.5"
4
+ gem 'mysql'
5
+ gem 'ruby-debug'
6
+ gem "authlogic", '2.1.3'
7
+
8
+ gem 'ruby-debug'
9
+ gem 'mocha', '>= 0.9.8'
10
+ gem 'redgreen'
11
+ gem 'factory_girl'
12
+ gem 'shoulda'
13
+ gem 'treetop', '>=1.2.4'
14
+ gem 'term-ansicolor', '>=1.0.3', :require => 'term/ansicolor'
15
+ gem 'cucumber', '>=0.1.13', :require => 'cucumber'
16
+ gem 'polyglot', '>=0.2.4'
17
+ gem "rcov", '>=0.8.1.2.0'
18
+ gem "webrat", '>=0.4.4'
19
+ gem 'redgreen'
20
+
21
+ # gem 'rspec', '>=1.1.12', :require_as => 'spec'
22
+ # gem 'rspec-rails', '>=1.1.12', :require_as => 'spec/rails'
23
+ # only required if you want to use selenium for testing
24
+ # gem 'selenium-client', :require_as => 'selenium/client'
25
+ # gem 'database_cleaner'
26
+
27
+ gem 'muck-users', '0.3.13', :require => 'muck_users'
28
+ gem 'muck-engine', :require => 'muck_engine', :path => File.join(File.dirname(__FILE__), *%w(.. .. ..))
29
+ # gem 'muck-engine', :require => 'muck_engine', :path => "~/projects/muck-engine"
30
+ # gem 'muck-users', :require => 'muck_users', :path => "~/projects/muck-users"
@@ -11,5 +11,3 @@ require 'tasks/rails'
11
11
 
12
12
  require 'muck_engine/tasks'
13
13
  require 'muck_users/tasks'
14
- require 'muck_comments/tasks'
15
- require 'muck_activities/tasks'
@@ -105,5 +105,19 @@ module Rails
105
105
  end
106
106
  end
107
107
 
108
+ class Rails::Boot
109
+ def run
110
+ load_initializer
111
+
112
+ Rails::Initializer.class_eval do
113
+ def load_gems
114
+ @bundler_loaded ||= Bundler.require :default, Rails.env
115
+ end
116
+ end
117
+
118
+ Rails::Initializer.run(:set_load_path)
119
+ end
120
+ end
121
+
108
122
  # All that for this:
109
123
  Rails.boot!
@@ -0,0 +1,20 @@
1
+ begin
2
+ require "rubygems"
3
+ require "bundler"
4
+ rescue LoadError
5
+ raise "Could not load the bundler gem. Install it with `gem install bundler`."
6
+ end
7
+
8
+ if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
9
+ raise RuntimeError, "Your bundler version is too old." +
10
+ "Run `gem install bundler` to upgrade."
11
+ end
12
+
13
+ begin
14
+ # Set up load paths for all bundled gems
15
+ ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
16
+ Bundler.setup
17
+ rescue Bundler::GemNotFound
18
+ raise RuntimeError, "Bundler couldn't find some gems." +
19
+ "Did you run `bundle install`?"
20
+ end
@@ -4,26 +4,32 @@ class Admin::Muck::DefaultControllerTest < ActionController::TestCase
4
4
 
5
5
  tests Admin::DefaultController
6
6
 
7
- context "GET to admin index" do
7
+ context "logged in as admin" do
8
+
9
+ setup do
10
+ User.destroy_all
11
+ activate_authlogic
12
+ @admin = Factory(:user)
13
+ @admin_role = Factory(:role, :rolename => 'administrator')
14
+ @admin.roles << @admin_role
15
+ login_as @admin
16
+ end
17
+
18
+ context "GET to admin index" do
19
+ setup do
20
+ get :index
21
+ end
22
+ should_respond_with :success
23
+ should_render_template :index
24
+ end
25
+
26
+ end
27
+
28
+ context "not logged in" do
8
29
  setup do
9
- @user = stub(:display_name => 'test')
10
- @controller.stubs(:current_user).returns(@user)
11
- @controller.stubs(:login_required).returns(true)
12
- @controller.stubs(:admin_access_required).returns(true)
13
30
  get :index
14
31
  end
15
- should_respond_with :success
16
- should_render_template :index
32
+ should_respond_with :redirect
17
33
  end
18
34
 
19
- # TODO add tests to confirm admin UI access requires login and role 'administrator'
20
- # context "GET to admin index not logged in" do
21
- # setup do
22
- # @controller.stubs(:login_required).returns(false)
23
- # @controller.stubs(:admin_access_required).returns(false)
24
- # get :index
25
- # end
26
- # should_respond_with :redirect
27
- # end
28
-
29
35
  end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class HelperControllerTest < ActionController::TestCase
4
+
5
+ tests Muck::HelperController
6
+
7
+ context "load_states_for_country" do
8
+
9
+ setup do
10
+ @country = Factory(:country)
11
+ @state = Factory(:state, :country => @country)
12
+ get :load_states_for_country, :id => @country.to_param, :format => 'json'
13
+ end
14
+ should_respond_with :success
15
+ should "include state in resulting json" do
16
+ assert @response.body.include?(@state.name)
17
+ end
18
+ end
19
+
20
+ end
@@ -1,12 +1,28 @@
1
1
  $:.reject! { |e| e.include? 'TextMate' }
2
2
  ENV["RAILS_ENV"] = "test"
3
3
  require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
4
- gem 'muck-engine'
5
- require 'muck_test_helper'
6
4
 
5
+ require 'test_help'
6
+ require 'ruby-debug'
7
+ require 'authlogic/test_case'
8
+ require 'muck_test_helper'
9
+ require 'pp'
7
10
 
8
11
  class ActiveSupport::TestCase
9
12
  include MuckTestMethods
10
13
  self.use_transactional_fixtures = true
11
14
  self.use_instantiated_fixtures = false
15
+
16
+ include Authlogic::TestCase
17
+
18
+ def login_as(user)
19
+ success = UserSession.create(user)
20
+ if !success
21
+ errors = user.errors.full_messages.to_sentence
22
+ message = 'User has not been activated' if !user.active?
23
+ raise "could not login as #{user.to_param}. Please make sure the user is valid. #{message} #{errors}"
24
+ end
25
+ UserSession.find
26
+ end
27
+
12
28
  end
@@ -0,0 +1,86 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class CountryTest < ActiveSupport::TestCase
4
+
5
+ context "a country instance" do
6
+
7
+ setup do
8
+ @country = Factory(:country)
9
+ end
10
+
11
+ subject { @country }
12
+ should_have_many :states
13
+ should_scope_by_name
14
+
15
+ context "us" do
16
+ setup do
17
+ Country.destroy_all
18
+ @us_country = Factory(:country, :abbreviation => 'US')
19
+ @other_country = Factory(:country)
20
+ end
21
+ should "find countries with abbreviation 'US'" do
22
+ assert_equal @us_country, Country.us
23
+ end
24
+ should "not find other countries" do
25
+ assert_not_equal @other_country, Country.us
26
+ end
27
+ end
28
+
29
+ context "uk_country?" do
30
+ setup do
31
+ Country.destroy_all
32
+ @eng_country = Factory(:country, :abbreviation => 'ENG')
33
+ @ie_country = Factory(:country, :abbreviation => 'IE')
34
+ @wal_country = Factory(:country, :abbreviation => 'WAL')
35
+ @sct_country = Factory(:country, :abbreviation => 'SCT')
36
+ @other_country = Factory(:country)
37
+ end
38
+ should "determine if the country is a UK country" do
39
+ assert Country.uk_country?(@eng_country.id, true)
40
+ assert Country.uk_country?(@ie_country.id, true)
41
+ assert Country.uk_country?(@wal_country.id, true)
42
+ assert Country.uk_country?(@sct_country.id, true)
43
+ assert !Country.uk_country?(@other_country.id, true)
44
+ end
45
+ should "be able to use country object or id" do
46
+ assert Country.uk_country?(@eng_country, true)
47
+ assert Country.uk_country?(@eng_country.id, true)
48
+ end
49
+ end
50
+
51
+ context "canada?" do
52
+ setup do
53
+ Country.destroy_all
54
+ @canada = Factory(:country, :abbreviation => 'CA')
55
+ @other_country = Factory(:country)
56
+ end
57
+ should "determine if the country is canada" do
58
+ assert Country.canada?(@canada.id, true)
59
+ assert !Country.canada?(@other_country.id, true)
60
+ end
61
+ end
62
+
63
+ context "build_state_prompts" do
64
+ setup do
65
+ Country.destroy_all
66
+ @us_country = Factory(:country, :abbreviation => 'US')
67
+ @eng_country = Factory(:country, :abbreviation => 'ENG')
68
+ @canada = Factory(:country, :abbreviation => 'CA')
69
+ end
70
+ should "return county for UK" do
71
+ label, prompt = Country.build_state_prompts(@eng_country)
72
+ assert prompt.include?('county')
73
+ end
74
+ should "return province for canada" do
75
+ label, prompt = Country.build_state_prompts(@canada)
76
+ assert prompt.include?('province')
77
+ end
78
+ should "return state for other" do
79
+ label, prompt = Country.build_state_prompts(@us_country)
80
+ assert prompt.include?('state')
81
+ end
82
+ end
83
+
84
+ end
85
+
86
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class LangaugeTest < ActiveSupport::TestCase
4
+
5
+ context "a language instance" do
6
+
7
+ context "locale_id" do
8
+ setup do
9
+ @language = Factory(:unmodified_language, :locale => 'zz', :supported => true)
10
+ I18n.stubs(:locale).returns(:zz)
11
+ end
12
+ should "find the language id for the current locale" do
13
+ assert_equal @language.id, Language.locale_id(true)
14
+ end
15
+ end
16
+
17
+ context "supported_locale?" do
18
+ setup do
19
+ @supported_locale = 'zz'
20
+ @not_supported_locale = 'aa'
21
+ @supported_language = Factory(:unmodified_language, :locale => @supported_locale, :supported => true)
22
+ end
23
+ should "indicate the locale is supported" do
24
+ assert Language.supported_locale?(@supported_locale, true)
25
+ end
26
+ should "indicate the locale is not supported" do
27
+ assert !Language.supported_locale?(@not_supported_locale, true)
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class StateTest < ActiveSupport::TestCase
4
+
5
+ context "a state instance" do
6
+
7
+ setup do
8
+ @state = Factory(:state)
9
+ end
10
+
11
+ subject { @state }
12
+
13
+ should_belong_to :country
14
+ should_scope_by_name
15
+
16
+ end
17
+
18
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muck-engine
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 57
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 4
8
- - 26
9
- version: 0.4.26
9
+ - 27
10
+ version: 0.4.27
10
11
  platform: ruby
11
12
  authors:
12
13
  - Justin Ball
@@ -15,16 +16,18 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-05-14 00:00:00 -06:00
19
+ date: 2010-05-31 00:00:00 -06:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
23
  name: validation_reflection
23
24
  prerelease: false
24
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
25
27
  requirements:
26
28
  - - ">="
27
29
  - !ruby/object:Gem::Version
30
+ hash: 3
28
31
  segments:
29
32
  - 0
30
33
  version: "0"
@@ -34,9 +37,11 @@ dependencies:
34
37
  name: will_paginate
35
38
  prerelease: false
36
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
37
41
  requirements:
38
42
  - - ">="
39
43
  - !ruby/object:Gem::Version
44
+ hash: 3
40
45
  segments:
41
46
  - 0
42
47
  version: "0"
@@ -46,26 +51,44 @@ dependencies:
46
51
  name: git
47
52
  prerelease: false
48
53
  requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
49
55
  requirements:
50
56
  - - ">="
51
57
  - !ruby/object:Gem::Version
58
+ hash: 3
52
59
  segments:
53
60
  - 0
54
61
  version: "0"
55
62
  type: :runtime
56
63
  version_requirements: *id003
57
64
  - !ruby/object:Gem::Dependency
58
- name: shoulda
65
+ name: overlord
59
66
  prerelease: false
60
67
  requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
61
69
  requirements:
62
70
  - - ">="
63
71
  - !ruby/object:Gem::Version
72
+ hash: 3
64
73
  segments:
65
74
  - 0
66
75
  version: "0"
67
- type: :development
76
+ type: :runtime
68
77
  version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: shoulda
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id005
69
92
  description: The base engine for the muck system. Contains common tables, custom for, css and javascript.
70
93
  email: justin@tatemae.com
71
94
  executables: []
@@ -131,6 +154,9 @@ files:
131
154
  - install.rb
132
155
  - lib/action_controller/muck_application.rb
133
156
  - lib/action_mailer/muck_mailer.rb
157
+ - lib/active_record/acts/muck_country.rb
158
+ - lib/active_record/acts/muck_language.rb
159
+ - lib/active_record/acts/muck_state.rb
134
160
  - lib/active_record/muck_model.rb
135
161
  - lib/muck_engine.rb
136
162
  - lib/muck_engine/flash_errors.rb
@@ -726,6 +752,7 @@ files:
726
752
  - tasks/rails.rake
727
753
  - test/rails_root/.gitignore
728
754
  - test/rails_root/.rake_tasks
755
+ - test/rails_root/Gemfile
729
756
  - test/rails_root/Rakefile
730
757
  - test/rails_root/app/controllers/admin/default_controller.rb
731
758
  - test/rails_root/app/controllers/application_controller.rb
@@ -749,6 +776,7 @@ files:
749
776
  - test/rails_root/config/initializers/mime_types.rb
750
777
  - test/rails_root/config/initializers/requires.rb
751
778
  - test/rails_root/config/initializers/session_store.rb
779
+ - test/rails_root/config/preinitializer.rb
752
780
  - test/rails_root/config/routes.rb
753
781
  - test/rails_root/db/.keep
754
782
  - test/rails_root/db/migrate/20090320174818_create_muck_permissions_and_roles.rb
@@ -1333,13 +1361,17 @@ files:
1333
1361
  - test/rails_root/test/functional/.keep
1334
1362
  - test/rails_root/test/functional/admin/default_controller_test.rb
1335
1363
  - test/rails_root/test/functional/default_controller_test.rb
1364
+ - test/rails_root/test/functional/helper_controller_test.rb
1336
1365
  - test/rails_root/test/integration/.keep
1337
1366
  - test/rails_root/test/mocks/development/.keep
1338
1367
  - test/rails_root/test/mocks/test/.keep
1339
1368
  - test/rails_root/test/test_helper.rb
1340
1369
  - test/rails_root/test/unit/.keep
1341
1370
  - test/rails_root/test/unit/basic_mailer_test.rb
1371
+ - test/rails_root/test/unit/country_test.rb
1372
+ - test/rails_root/test/unit/language_test.rb
1342
1373
  - test/rails_root/test/unit/muck_engine_helper_test.rb
1374
+ - test/rails_root/test/unit/state_test.rb
1343
1375
  - test/rails_root/vendor/plugins/ssl_requirement/README
1344
1376
  - test/rails_root/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb
1345
1377
  - test/rails_root/vendor/plugins/ssl_requirement/test/ssl_requirement_test.rb
@@ -1354,23 +1386,27 @@ rdoc_options:
1354
1386
  require_paths:
1355
1387
  - lib
1356
1388
  required_ruby_version: !ruby/object:Gem::Requirement
1389
+ none: false
1357
1390
  requirements:
1358
1391
  - - ">="
1359
1392
  - !ruby/object:Gem::Version
1393
+ hash: 3
1360
1394
  segments:
1361
1395
  - 0
1362
1396
  version: "0"
1363
1397
  required_rubygems_version: !ruby/object:Gem::Requirement
1398
+ none: false
1364
1399
  requirements:
1365
1400
  - - ">="
1366
1401
  - !ruby/object:Gem::Version
1402
+ hash: 3
1367
1403
  segments:
1368
1404
  - 0
1369
1405
  version: "0"
1370
1406
  requirements: []
1371
1407
 
1372
1408
  rubyforge_project: muck-engine
1373
- rubygems_version: 1.3.6
1409
+ rubygems_version: 1.3.7
1374
1410
  signing_key:
1375
1411
  specification_version: 3
1376
1412
  summary: The base engine for the muck system.
@@ -1390,6 +1426,7 @@ test_files:
1390
1426
  - test/rails_root/config/initializers/mime_types.rb
1391
1427
  - test/rails_root/config/initializers/requires.rb
1392
1428
  - test/rails_root/config/initializers/session_store.rb
1429
+ - test/rails_root/config/preinitializer.rb
1393
1430
  - test/rails_root/config/routes.rb
1394
1431
  - test/rails_root/db/migrate/20090320174818_create_muck_permissions_and_roles.rb
1395
1432
  - test/rails_root/db/migrate/20090402234137_create_languages.rb
@@ -1402,8 +1439,12 @@ test_files:
1402
1439
  - test/rails_root/script/create_project.rb
1403
1440
  - test/rails_root/test/functional/admin/default_controller_test.rb
1404
1441
  - test/rails_root/test/functional/default_controller_test.rb
1442
+ - test/rails_root/test/functional/helper_controller_test.rb
1405
1443
  - test/rails_root/test/test_helper.rb
1406
1444
  - test/rails_root/test/unit/basic_mailer_test.rb
1445
+ - test/rails_root/test/unit/country_test.rb
1446
+ - test/rails_root/test/unit/language_test.rb
1407
1447
  - test/rails_root/test/unit/muck_engine_helper_test.rb
1448
+ - test/rails_root/test/unit/state_test.rb
1408
1449
  - test/rails_root/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb
1409
1450
  - test/rails_root/vendor/plugins/ssl_requirement/test/ssl_requirement_test.rb