jpmobile 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/README.rdoc +227 -0
  2. data/Rakefile +6 -13
  3. data/lib/jpmobile/docomo_guid.rb +42 -0
  4. data/lib/jpmobile/filter.rb +1 -1
  5. data/lib/jpmobile/helpers.rb +2 -1
  6. data/lib/jpmobile/hook_action_controller.rb +12 -0
  7. data/lib/jpmobile/hook_action_view.rb +82 -72
  8. data/lib/jpmobile/{hook_abstract_request.rb → hook_request.rb} +1 -1
  9. data/lib/jpmobile/mobile/au.rb +9 -3
  10. data/lib/jpmobile/mobile/z_display_info_docomo.rb +10 -2
  11. data/lib/jpmobile/mobile/z_ip_addresses_au.rb +1 -26
  12. data/lib/jpmobile/mobile/z_ip_addresses_willcom.rb +2 -4
  13. data/lib/jpmobile/rack/auth.rb +55 -0
  14. data/lib/jpmobile/rack/combined_logger.rb +54 -0
  15. data/lib/jpmobile/rack/request.rb +7 -0
  16. data/lib/jpmobile/rack/trans_sid.rb +14 -0
  17. data/lib/jpmobile/trans_sid.rb +70 -62
  18. data/lib/jpmobile/version.rb +1 -1
  19. data/test/{au_test.rb → legacy/au_test.rb} +0 -0
  20. data/test/{autoload_test.rb → legacy/autoload_test.rb} +0 -0
  21. data/test/{docomo_test.rb → legacy/docomo_test.rb} +0 -0
  22. data/test/{emoticon_functional_test.rb → legacy/emoticon_functional_test.rb} +1 -1
  23. data/test/{emoticon_test.rb → legacy/emoticon_test.rb} +0 -0
  24. data/test/{filter_test.rb → legacy/filter_test.rb} +0 -0
  25. data/test/{helper.rb → legacy/helper.rb} +4 -5
  26. data/test/{helpers_test.rb → legacy/helpers_test.rb} +1 -1
  27. data/test/{softbank_test.rb → legacy/softbank_test.rb} +0 -0
  28. data/test/{willcom_test.rb → legacy/willcom_test.rb} +0 -0
  29. data/test/rails/overrides/app/controllers/application.rb +5 -0
  30. data/test/rails/overrides/app/controllers/docomo_guid_controller.rb +13 -0
  31. data/test/rails/overrides/app/controllers/filter_controller.rb +26 -0
  32. data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +5 -0
  33. data/test/rails/overrides/app/controllers/template_path_controller.rb +6 -0
  34. data/test/rails/overrides/app/controllers/trans_sid_controller.rb +28 -0
  35. data/test/rails/overrides/app/views/filter/index.html.erb +0 -0
  36. data/test/rails/overrides/app/views/hankaku_filter/index.html.erb +0 -0
  37. data/test/rails/overrides/app/views/template_path/_partial.html.erb +1 -0
  38. data/test/rails/overrides/app/views/template_path/_partial_mobile.html.erb +1 -0
  39. data/test/rails/overrides/app/views/template_path/_partial_mobile_docomo.html.erb +1 -0
  40. data/test/rails/overrides/app/views/template_path/index.html.erb +1 -0
  41. data/test/rails/overrides/app/views/template_path/index_mobile.html.erb +1 -0
  42. data/test/rails/overrides/app/views/template_path/index_mobile_docomo.html.erb +1 -0
  43. data/test/rails/overrides/app/views/template_path/partial.html.erb +2 -0
  44. data/test/rails/overrides/lib/tasks/rspec.rake +165 -0
  45. data/test/rails/overrides/spec/controllers/docomo_guid_spec.rb +77 -0
  46. data/test/rails/overrides/spec/controllers/docomo_spec.rb +28 -0
  47. data/test/rails/overrides/spec/controllers/emobile_spec.rb +35 -0
  48. data/test/rails/overrides/spec/controllers/filter_spec.rb +157 -0
  49. data/test/rails/overrides/spec/controllers/pc_spec.rb +11 -0
  50. data/test/rails/overrides/spec/controllers/softbank_emulator_spec.rb +40 -0
  51. data/test/rails/overrides/spec/controllers/template_path_spec.rb +115 -0
  52. data/test/rails/overrides/spec/controllers/trans_sid_spec.rb +98 -0
  53. data/test/rails/overrides/spec/helpers/helpers_spec.rb +13 -0
  54. data/test/rails/overrides/spec/rcov.opts +2 -0
  55. data/test/rails/overrides/spec/rspec.rake +165 -0
  56. data/test/rails/overrides/spec/spec.opts +4 -0
  57. data/test/rails/overrides/spec/spec_helper.rb +47 -0
  58. data/test/rails/rails_root/README +256 -0
  59. data/test/rails/rails_root/Rakefile +10 -0
  60. data/test/rails/rails_root/app/controllers/application.rb +5 -0
  61. data/test/rails/rails_root/app/controllers/docomo_guid_controller.rb +13 -0
  62. data/test/rails/rails_root/app/controllers/filter_controller.rb +26 -0
  63. data/test/rails/rails_root/app/controllers/mobile_spec_controller.rb +5 -0
  64. data/test/rails/rails_root/app/controllers/template_path_controller.rb +6 -0
  65. data/test/rails/rails_root/app/controllers/trans_sid_controller.rb +26 -0
  66. data/test/rails/rails_root/app/helpers/application_helper.rb +3 -0
  67. data/test/rails/rails_root/app/views/template_path/index.html.erb +1 -0
  68. data/test/rails/rails_root/app/views/template_path/index_mobile.html.erb +1 -0
  69. data/test/rails/rails_root/app/views/template_path/index_mobile_docomo.html.erb +1 -0
  70. data/test/rails/rails_root/config/boot.rb +109 -0
  71. data/test/rails/rails_root/config/database.yml +22 -0
  72. data/test/rails/rails_root/config/environment.rb +75 -0
  73. data/test/rails/rails_root/config/environments/development.rb +17 -0
  74. data/test/rails/rails_root/config/environments/production.rb +24 -0
  75. data/test/rails/rails_root/config/environments/test.rb +22 -0
  76. data/test/rails/rails_root/config/initializers/inflections.rb +10 -0
  77. data/test/rails/rails_root/config/initializers/mime_types.rb +5 -0
  78. data/test/rails/rails_root/config/initializers/new_rails_defaults.rb +17 -0
  79. data/test/rails/rails_root/config/locales/en.yml +5 -0
  80. data/test/rails/rails_root/config/routes.rb +43 -0
  81. data/test/rails/rails_root/db/development.sqlite3 +0 -0
  82. data/test/rails/rails_root/db/schema.rb +14 -0
  83. data/test/rails/rails_root/db/test.sqlite3 +0 -0
  84. data/test/rails/rails_root/doc/README_FOR_APP +5 -0
  85. data/test/rails/rails_root/lib/tasks/rspec.rake +165 -0
  86. data/test/rails/rails_root/log/development.log +38 -0
  87. data/test/rails/rails_root/log/production.log +0 -0
  88. data/test/rails/rails_root/log/server.log +0 -0
  89. data/test/rails/rails_root/log/test.log +401 -0
  90. data/test/rails/rails_root/public/404.html +30 -0
  91. data/test/rails/rails_root/public/422.html +30 -0
  92. data/test/rails/rails_root/public/500.html +33 -0
  93. data/test/rails/rails_root/public/dispatch.cgi +10 -0
  94. data/test/rails/rails_root/public/dispatch.fcgi +24 -0
  95. data/test/rails/rails_root/public/dispatch.rb +10 -0
  96. data/test/rails/rails_root/public/favicon.ico +0 -0
  97. data/test/rails/rails_root/public/images/rails.png +0 -0
  98. data/test/rails/rails_root/public/index.html +274 -0
  99. data/test/rails/rails_root/public/javascripts/application.js +2 -0
  100. data/test/rails/rails_root/public/javascripts/controls.js +963 -0
  101. data/test/rails/rails_root/public/javascripts/dragdrop.js +973 -0
  102. data/test/rails/rails_root/public/javascripts/effects.js +1128 -0
  103. data/test/rails/rails_root/public/javascripts/prototype.js +4320 -0
  104. data/test/rails/rails_root/public/robots.txt +5 -0
  105. data/test/rails/rails_root/script/about +4 -0
  106. data/test/rails/rails_root/script/console +3 -0
  107. data/test/rails/rails_root/script/dbconsole +3 -0
  108. data/test/rails/rails_root/script/destroy +3 -0
  109. data/test/rails/rails_root/script/generate +3 -0
  110. data/test/rails/rails_root/script/performance/benchmarker +3 -0
  111. data/test/rails/rails_root/script/performance/profiler +3 -0
  112. data/test/rails/rails_root/script/performance/request +3 -0
  113. data/test/rails/rails_root/script/plugin +3 -0
  114. data/test/rails/rails_root/script/process/inspector +3 -0
  115. data/test/rails/rails_root/script/process/reaper +3 -0
  116. data/test/rails/rails_root/script/process/spawner +3 -0
  117. data/test/rails/rails_root/script/runner +3 -0
  118. data/test/rails/rails_root/script/server +3 -0
  119. data/test/rails/rails_root/spec/controllers/docomo_guid_spec.rb +77 -0
  120. data/test/rails/rails_root/spec/controllers/docomo_spec.rb +28 -0
  121. data/test/rails/rails_root/spec/controllers/emobile_spec.rb +35 -0
  122. data/test/rails/rails_root/spec/controllers/filter_spec.rb +157 -0
  123. data/test/rails/rails_root/spec/controllers/pc_spec.rb +11 -0
  124. data/test/rails/rails_root/spec/controllers/softbank_emulator_spec.rb +40 -0
  125. data/test/rails/rails_root/spec/controllers/template_path_spec.rb +85 -0
  126. data/test/rails/rails_root/spec/controllers/trans_sid_spec.rb +96 -0
  127. data/test/rails/rails_root/spec/helpers/helpers_spec.rb +13 -0
  128. data/test/rails/rails_root/spec/rcov.opts +2 -0
  129. data/test/rails/rails_root/spec/rspec.rake +165 -0
  130. data/test/rails/rails_root/spec/spec.opts +4 -0
  131. data/test/rails/rails_root/spec/spec_helper.rb +47 -0
  132. data/test/rails/rails_root/test/performance/browsing_test.rb +9 -0
  133. data/test/rails/rails_root/test/test_helper.rb +38 -0
  134. data/test/rails/rails_root/vendor/plugins/jpmobile/CHANGELOG +7 -0
  135. data/test/rails/rails_root/vendor/plugins/jpmobile/MIT-LICENSE +7 -0
  136. data/{README → test/rails/rails_root/vendor/plugins/jpmobile/README.rdoc} +15 -17
  137. data/test/rails/rails_root/vendor/plugins/jpmobile/Rakefile +116 -0
  138. data/test/rails/rails_root/vendor/plugins/jpmobile/init.rb +3 -0
  139. data/test/rails/rails_root/vendor/plugins/jpmobile/install.rb +1 -0
  140. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile.rb +42 -0
  141. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/datum_conv.rb +72 -0
  142. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/docomo_guid.rb +42 -0
  143. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/email.rb +19 -0
  144. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon.rb +123 -0
  145. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/au.rb +1287 -0
  146. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/conversion_table.rb +3908 -0
  147. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/docomo.rb +255 -0
  148. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/softbank.rb +477 -0
  149. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/z_combine.rb +20 -0
  150. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/filter.rb +173 -0
  151. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/helpers.rb +185 -0
  152. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_controller.rb +11 -0
  153. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_view.rb +142 -0
  154. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_request.rb +13 -0
  155. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/abstract_mobile.rb +73 -0
  156. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/au.rb +97 -0
  157. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/display.rb +33 -0
  158. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/docomo.rb +97 -0
  159. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/emobile.rb +17 -0
  160. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/softbank.rb +110 -0
  161. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/willcom.rb +39 -0
  162. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_display_info_docomo.rb +688 -0
  163. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_au.rb +22 -0
  164. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_docomo.rb +12 -0
  165. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_emobile.rb +10 -0
  166. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_softbank.rb +17 -0
  167. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_willcom.rb +117 -0
  168. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/position.rb +67 -0
  169. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/request_with_mobile.rb +44 -0
  170. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/trans_sid.rb +105 -0
  171. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/util.rb +21 -0
  172. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/version.rb +9 -0
  173. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/spec.opts +6 -0
  174. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/spec_helper.rb +36 -0
  175. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/detect_by_email_spec.rb +31 -0
  176. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/detect_by_ua_spec.rb +42 -0
  177. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/is_carrier_spec.rb +93 -0
  178. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/spec_helper.rb +5 -0
  179. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/util_spec.rb +28 -0
  180. data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/valid_ip_spec.rb +60 -0
  181. data/test/rails/rails_root/vendor/plugins/jpmobile/tasks/jpmobile_tasks.rake +59 -0
  182. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/emoji/genregexp.rb +47 -0
  183. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_au_emoticon_table.rb +34 -0
  184. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_docomo_emoticon_table.rb +34 -0
  185. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_emoticon_conversion_table.rb +107 -0
  186. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_softbank_emoticon_table.rb +32 -0
  187. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/list_gps_unsupported_au.rb +23 -0
  188. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_display_info_docomo.rb +45 -0
  189. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_ip_addresses_au.rb +29 -0
  190. data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_ip_addresses_willcom.rb +17 -0
  191. data/tools/update_ip_addresses_au.rb +15 -5
  192. metadata +188 -22
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe Jpmobile::Helpers do
4
+ include Jpmobile::Helpers
5
+ it "docomo_guid_link_to が guid=ON を付けたリンクを生成すること" do
6
+ docomo_guid_link_to("STRING", :controller => "MyController", :action => "myaction").should == %{<a href="/mycontroller/myaction?guid=ON">STRING</a>}
7
+ end
8
+
9
+ it "softbank_location_link_to がリンク先にパラメータを含んでいても正常に動作すること" do
10
+ # http://d.hatena.ne.jp/mizincogrammer/20090123/1232702067
11
+ softbank_location_link_to("STRING", :controller => "MyController", :action => "myaction", :p => "param").should == %{<a href="location:auto?url=http://test.host/mycontroller/myaction&p=param">STRING</a>}
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ --exclude "spec/*,gems/*"
2
+ --rails
@@ -0,0 +1,165 @@
1
+ gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
2
+
3
+ # Don't load rspec if running "rake gems:*"
4
+ unless ARGV.any? {|a| a =~ /^gems/}
5
+
6
+ begin
7
+ require 'spec/rake/spectask'
8
+ rescue MissingSourceFile
9
+ module Spec
10
+ module Rake
11
+ class SpecTask
12
+ def initialize(name)
13
+ task name do
14
+ # if rspec-rails is a configured gem, this will output helpful material and exit ...
15
+ require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
16
+
17
+ # ... otherwise, do this:
18
+ raise <<-MSG
19
+
20
+ #{"*" * 80}
21
+ * You are trying to run an rspec rake task defined in
22
+ * #{__FILE__},
23
+ * but rspec can not be found in vendor/gems, vendor/plugins or system gems.
24
+ #{"*" * 80}
25
+ MSG
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ Rake.application.instance_variable_get('@tasks').delete('default')
34
+
35
+ spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
36
+ task :noop do
37
+ end
38
+
39
+ task :default => :spec
40
+ task :stats => "spec:statsetup"
41
+
42
+ desc "Run all specs in spec directory (excluding plugin specs)"
43
+ Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
44
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
45
+ t.spec_files = FileList['spec/**/*/*_spec.rb']
46
+ end
47
+
48
+ namespace :spec do
49
+ desc "Run all specs in spec directory with RCov (excluding plugin specs)"
50
+ Spec::Rake::SpecTask.new(:rcov) do |t|
51
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
52
+ t.spec_files = FileList['spec/**/*/*_spec.rb']
53
+ t.rcov = true
54
+ t.rcov_opts = lambda do
55
+ IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
56
+ end
57
+ end
58
+
59
+ desc "Print Specdoc for all specs (excluding plugin specs)"
60
+ Spec::Rake::SpecTask.new(:doc) do |t|
61
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
62
+ t.spec_files = FileList['spec/**/*/*_spec.rb']
63
+ end
64
+
65
+ desc "Print Specdoc for all plugin examples"
66
+ Spec::Rake::SpecTask.new(:plugin_doc) do |t|
67
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
68
+ t.spec_files = FileList['vendor/plugins/**/spec/**/*/*_spec.rb'].exclude('vendor/plugins/rspec/*')
69
+ end
70
+
71
+ [:models, :controllers, :views, :helpers, :lib].each do |sub|
72
+ desc "Run the code examples in spec/#{sub}"
73
+ Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
74
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
75
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
76
+ end
77
+ end
78
+
79
+ desc "Run the code examples in vendor/plugins (except RSpec's own)"
80
+ Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
81
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
82
+ t.spec_files = FileList['vendor/plugins/**/spec/**/*/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
83
+ end
84
+
85
+ namespace :plugins do
86
+ desc "Runs the examples for rspec_on_rails"
87
+ Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
88
+ t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
89
+ t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*/*_spec.rb']
90
+ end
91
+ end
92
+
93
+ # Setup specs for stats
94
+ task :statsetup do
95
+ require 'code_statistics'
96
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
97
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
98
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
99
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
100
+ ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
101
+ ::STATS_DIRECTORIES << %w(Routing\ specs spec/lib) if File.exist?('spec/routing')
102
+ ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
103
+ ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
104
+ ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
105
+ ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
106
+ ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
107
+ ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
108
+ end
109
+
110
+ namespace :db do
111
+ namespace :fixtures do
112
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z."
113
+ task :load => :environment do
114
+ ActiveRecord::Base.establish_connection(Rails.env)
115
+ base_dir = File.join(Rails.root, 'spec', 'fixtures')
116
+ fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
117
+
118
+ require 'active_record/fixtures'
119
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
120
+ Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ namespace :server do
127
+ daemonized_server_pid = File.expand_path("#{RAILS_ROOT}/tmp/pids/spec_server.pid")
128
+
129
+ desc "start spec_server."
130
+ task :start do
131
+ if File.exist?(daemonized_server_pid)
132
+ $stderr.puts "spec_server is already running."
133
+ else
134
+ $stderr.puts %Q{Starting up spec_server ...}
135
+ FileUtils.mkdir_p('tmp/pids') unless test ?d, 'tmp/pids'
136
+ system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid)
137
+ end
138
+ end
139
+
140
+ desc "stop spec_server."
141
+ task :stop do
142
+ unless File.exist?(daemonized_server_pid)
143
+ $stderr.puts "No server running."
144
+ else
145
+ $stderr.puts "Shutting down spec_server ..."
146
+ system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) &&
147
+ File.delete(daemonized_server_pid)
148
+ end
149
+ end
150
+
151
+ desc "restart spec_server."
152
+ task :restart => [:stop, :start]
153
+
154
+ desc "check if spec server is running"
155
+ task :status do
156
+ if File.exist?(daemonized_server_pid)
157
+ $stderr.puts %Q{spec_server is running (PID: #{File.read(daemonized_server_pid).gsub("\n","")})}
158
+ else
159
+ $stderr.puts "No server running."
160
+ end
161
+ end
162
+ end
163
+ end
164
+
165
+ end
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,47 @@
1
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
+ # from the project root directory.
3
+ ENV["RAILS_ENV"] ||= 'test'
4
+ require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
5
+ require 'spec/autorun'
6
+ require 'spec/rails'
7
+
8
+ Spec::Runner.configure do |config|
9
+ # If you're not using ActiveRecord you should remove these
10
+ # lines, delete config/database.yml and disable :active_record
11
+ # in your config/boot.rb
12
+ config.use_transactional_fixtures = true
13
+ config.use_instantiated_fixtures = false
14
+ config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
15
+
16
+ # == Fixtures
17
+ #
18
+ # You can declare fixtures for each example_group like this:
19
+ # describe "...." do
20
+ # fixtures :table_a, :table_b
21
+ #
22
+ # Alternatively, if you prefer to declare them only once, you can
23
+ # do so right here. Just uncomment the next line and replace the fixture
24
+ # names with your fixtures.
25
+ #
26
+ # config.global_fixtures = :table_a, :table_b
27
+ #
28
+ # If you declare global fixtures, be aware that they will be declared
29
+ # for all of your examples, even those that don't use them.
30
+ #
31
+ # You can also declare which fixtures to use (for example fixtures for test/fixtures):
32
+ #
33
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
34
+ #
35
+ # == Mock Framework
36
+ #
37
+ # RSpec uses it's own mocking framework by default. If you prefer to
38
+ # use mocha, flexmock or RR, uncomment the appropriate line:
39
+ #
40
+ # config.mock_with :mocha
41
+ # config.mock_with :flexmock
42
+ # config.mock_with :rr
43
+ #
44
+ # == Notes
45
+ #
46
+ # For more information take a look at Spec::Runner::Configuration and Spec::Runner
47
+ end
@@ -0,0 +1,256 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb" templates
7
+ that are primarily responsible for inserting pre-built data in between HTML tags.
8
+ The model contains the "smart" domain objects (such as Account, Product, Person,
9
+ Post) that holds all the business logic and knows how to persist themselves to
10
+ a database. The controller handles the incoming requests (such as Save New Account,
11
+ Update Product, Show Post) by manipulating the model and directing data to the view.
12
+
13
+ In Rails, the model is handled by what's called an object-relational mapping
14
+ layer entitled Active Record. This layer allows you to present the data from
15
+ database rows as objects and embellish these data objects with business logic
16
+ methods. You can read more about Active Record in
17
+ link:files/vendor/rails/activerecord/README.html.
18
+
19
+ The controller and view are handled by the Action Pack, which handles both
20
+ layers by its two parts: Action View and Action Controller. These two layers
21
+ are bundled in a single package due to their heavy interdependence. This is
22
+ unlike the relationship between the Active Record and Action Pack that is much
23
+ more separate. Each of these packages can be used independently outside of
24
+ Rails. You can read more about Action Pack in
25
+ link:files/vendor/rails/actionpack/README.html.
26
+
27
+
28
+ == Getting Started
29
+
30
+ 1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
31
+ and your application name. Ex: rails myapp
32
+ 2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
33
+ 3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
34
+ 4. Follow the guidelines to start developing your application
35
+
36
+
37
+ == Web Servers
38
+
39
+ By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise
40
+ Rails will use WEBrick, the webserver that ships with Ruby. When you run script/server,
41
+ Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
42
+ that you can always get up and running quickly.
43
+
44
+ Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
45
+ suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
46
+ getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
47
+ More info at: http://mongrel.rubyforge.org
48
+
49
+ If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
50
+ Mongrel and WEBrick and also suited for production use, but requires additional
51
+ installation and currently only works well on OS X/Unix (Windows users are encouraged
52
+ to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
53
+ http://www.lighttpd.net.
54
+
55
+ And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
56
+ web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
57
+ for production.
58
+
59
+ But of course its also possible to run Rails on any platform that supports FCGI.
60
+ Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
61
+ please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
62
+
63
+
64
+ == Apache .htaccess example
65
+
66
+ # General Apache options
67
+ AddHandler fastcgi-script .fcgi
68
+ AddHandler cgi-script .cgi
69
+ Options +FollowSymLinks +ExecCGI
70
+
71
+ # If you don't want Rails to look in certain directories,
72
+ # use the following rewrite rules so that Apache won't rewrite certain requests
73
+ #
74
+ # Example:
75
+ # RewriteCond %{REQUEST_URI} ^/notrails.*
76
+ # RewriteRule .* - [L]
77
+
78
+ # Redirect all requests not available on the filesystem to Rails
79
+ # By default the cgi dispatcher is used which is very slow
80
+ #
81
+ # For better performance replace the dispatcher with the fastcgi one
82
+ #
83
+ # Example:
84
+ # RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
85
+ RewriteEngine On
86
+
87
+ # If your Rails application is accessed via an Alias directive,
88
+ # then you MUST also set the RewriteBase in this htaccess file.
89
+ #
90
+ # Example:
91
+ # Alias /myrailsapp /path/to/myrailsapp/public
92
+ # RewriteBase /myrailsapp
93
+
94
+ RewriteRule ^$ index.html [QSA]
95
+ RewriteRule ^([^.]+)$ $1.html [QSA]
96
+ RewriteCond %{REQUEST_FILENAME} !-f
97
+ RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
98
+
99
+ # In case Rails experiences terminal errors
100
+ # Instead of displaying this message you can supply a file here which will be rendered instead
101
+ #
102
+ # Example:
103
+ # ErrorDocument 500 /500.html
104
+
105
+ ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
106
+
107
+
108
+ == Debugging Rails
109
+
110
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
111
+ will help you debug it and get it back on the rails.
112
+
113
+ First area to check is the application log files. Have "tail -f" commands running
114
+ on the server.log and development.log. Rails will automatically display debugging
115
+ and runtime information to these files. Debugging info will also be shown in the
116
+ browser on requests from 127.0.0.1.
117
+
118
+ You can also log your own messages directly into the log file from your code using
119
+ the Ruby logger class from inside your controllers. Example:
120
+
121
+ class WeblogController < ActionController::Base
122
+ def destroy
123
+ @weblog = Weblog.find(params[:id])
124
+ @weblog.destroy
125
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
126
+ end
127
+ end
128
+
129
+ The result will be a message in your log file along the lines of:
130
+
131
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
132
+
133
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
134
+
135
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
136
+
137
+ * The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
138
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
139
+
140
+ These two online (and free) books will bring you up to speed on the Ruby language
141
+ and also on programming in general.
142
+
143
+
144
+ == Debugger
145
+
146
+ Debugger support is available through the debugger command when you start your Mongrel or
147
+ Webrick server with --debugger. This means that you can break out of execution at any point
148
+ in the code, investigate and change the model, AND then resume execution!
149
+ You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
150
+ Example:
151
+
152
+ class WeblogController < ActionController::Base
153
+ def index
154
+ @posts = Post.find(:all)
155
+ debugger
156
+ end
157
+ end
158
+
159
+ So the controller will accept the action, run the first line, then present you
160
+ with a IRB prompt in the server window. Here you can do things like:
161
+
162
+ >> @posts.inspect
163
+ => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
164
+ #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
165
+ >> @posts.first.title = "hello from a debugger"
166
+ => "hello from a debugger"
167
+
168
+ ...and even better is that you can examine how your runtime objects actually work:
169
+
170
+ >> f = @posts.first
171
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
172
+ >> f.
173
+ Display all 152 possibilities? (y or n)
174
+
175
+ Finally, when you're ready to resume execution, you enter "cont"
176
+
177
+
178
+ == Console
179
+
180
+ You can interact with the domain model by starting the console through <tt>script/console</tt>.
181
+ Here you'll have all parts of the application configured, just like it is when the
182
+ application is running. You can inspect domain models, change values, and save to the
183
+ database. Starting the script without arguments will launch it in the development environment.
184
+ Passing an argument will specify a different environment, like <tt>script/console production</tt>.
185
+
186
+ To reload your controllers and models after launching the console run <tt>reload!</tt>
187
+
188
+ == dbconsole
189
+
190
+ You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
191
+ You would be connected to the database with the credentials defined in database.yml.
192
+ Starting the script without arguments will connect you to the development database. Passing an
193
+ argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
194
+ Currently works for mysql, postgresql and sqlite.
195
+
196
+ == Description of Contents
197
+
198
+ app
199
+ Holds all the code that's specific to this particular application.
200
+
201
+ app/controllers
202
+ Holds controllers that should be named like weblogs_controller.rb for
203
+ automated URL mapping. All controllers should descend from ApplicationController
204
+ which itself descends from ActionController::Base.
205
+
206
+ app/models
207
+ Holds models that should be named like post.rb.
208
+ Most models will descend from ActiveRecord::Base.
209
+
210
+ app/views
211
+ Holds the template files for the view that should be named like
212
+ weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
213
+ syntax.
214
+
215
+ app/views/layouts
216
+ Holds the template files for layouts to be used with views. This models the common
217
+ header/footer method of wrapping views. In your views, define a layout using the
218
+ <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
219
+ call <% yield %> to render the view using this layout.
220
+
221
+ app/helpers
222
+ Holds view helpers that should be named like weblogs_helper.rb. These are generated
223
+ for you automatically when using script/generate for controllers. Helpers can be used to
224
+ wrap functionality for your views into methods.
225
+
226
+ config
227
+ Configuration files for the Rails environment, the routing map, the database, and other dependencies.
228
+
229
+ db
230
+ Contains the database schema in schema.rb. db/migrate contains all
231
+ the sequence of Migrations for your schema.
232
+
233
+ doc
234
+ This directory is where your application documentation will be stored when generated
235
+ using <tt>rake doc:app</tt>
236
+
237
+ lib
238
+ Application specific libraries. Basically, any kind of custom code that doesn't
239
+ belong under controllers, models, or helpers. This directory is in the load path.
240
+
241
+ public
242
+ The directory available for the web server. Contains subdirectories for images, stylesheets,
243
+ and javascripts. Also contains the dispatchers and the default HTML files. This should be
244
+ set as the DOCUMENT_ROOT of your web server.
245
+
246
+ script
247
+ Helper scripts for automation and generation.
248
+
249
+ test
250
+ Unit and functional tests along with fixtures. When using the script/generate scripts, template
251
+ test files will be generated for you and placed in this directory.
252
+
253
+ vendor
254
+ External libraries that the application depends on. Also includes the plugins subdirectory.
255
+ If the app has frozen rails, those gems also go here, under vendor/rails/.
256
+ This directory is in the load path.