enumerated_attribute 0.2.13 → 0.2.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.gitignore +0 -1
  2. data/Rakefile +11 -1
  3. data/lib/enumerated_attribute/rails_helpers.rb +12 -10
  4. data/spec/rails/config/environment.rb +1 -1
  5. data/spec/rails/spec/integrations/enum_select_spec.rb +1 -1
  6. data/spec/rails3/Gemfile +30 -0
  7. data/spec/rails3/README +244 -0
  8. data/spec/rails3/Rakefile +10 -0
  9. data/spec/rails3/app/controllers/application_controller.rb +10 -0
  10. data/spec/rails3/app/controllers/form_test_controller.rb +38 -0
  11. data/spec/rails3/app/helpers/application_helper.rb +3 -0
  12. data/spec/rails3/app/helpers/form_test_helper.rb +2 -0
  13. data/spec/rails3/app/models/user.rb +9 -0
  14. data/spec/rails3/app/views/form_test/form.html.erb +1 -0
  15. data/spec/rails3/app/views/form_test/form_for.html.erb +10 -0
  16. data/spec/rails3/app/views/form_test/form_tag.html.erb +9 -0
  17. data/spec/rails3/app/views/form_test/index.html.erb +6 -0
  18. data/spec/rails3/app/views/layouts/application.html.erb +11 -0
  19. data/spec/rails3/config.ru +4 -0
  20. data/spec/rails3/config/application.rb +46 -0
  21. data/spec/rails3/config/boot.rb +6 -0
  22. data/spec/rails3/config/database.yml +22 -0
  23. data/spec/rails3/config/environment.rb +5 -0
  24. data/spec/rails3/config/environments/development.rb +19 -0
  25. data/spec/rails3/config/environments/production.rb +42 -0
  26. data/spec/rails3/config/environments/test.rb +32 -0
  27. data/spec/rails3/config/initializers/backtrace_silencers.rb +7 -0
  28. data/spec/rails3/config/initializers/inflections.rb +10 -0
  29. data/spec/rails3/config/initializers/mime_types.rb +5 -0
  30. data/spec/rails3/config/initializers/secret_token.rb +7 -0
  31. data/spec/rails3/config/initializers/session_store.rb +8 -0
  32. data/spec/rails3/config/locales/en.yml +5 -0
  33. data/spec/rails3/config/routes.rb +58 -0
  34. data/spec/rails3/db/seeds.rb +7 -0
  35. data/spec/rails3/public/404.html +26 -0
  36. data/spec/rails3/public/422.html +26 -0
  37. data/spec/rails3/public/500.html +26 -0
  38. data/spec/rails3/public/favicon.ico +0 -0
  39. data/spec/rails3/public/images/rails.png +0 -0
  40. data/spec/rails3/public/index.html +279 -0
  41. data/spec/rails3/public/javascripts/application.js +2 -0
  42. data/spec/rails3/public/javascripts/controls.js +965 -0
  43. data/spec/rails3/public/javascripts/dragdrop.js +974 -0
  44. data/spec/rails3/public/javascripts/effects.js +1123 -0
  45. data/spec/rails3/public/javascripts/prototype.js +4874 -0
  46. data/spec/rails3/public/javascripts/rails.js +118 -0
  47. data/spec/rails3/public/robots.txt +5 -0
  48. data/spec/rails3/script/rails +9 -0
  49. data/spec/rails3/spec/integrations/enum_select_spec.rb +75 -0
  50. data/spec/rails3/spec/matchers.rb +12 -0
  51. data/spec/rails3/spec/rcov.opts +2 -0
  52. data/spec/rails3/spec/spec.opts +4 -0
  53. data/spec/rails3/spec/spec_helper.rb +41 -0
  54. data/spec/rails3/test/performance/browsing_test.rb +9 -0
  55. data/spec/rails3/test/test_helper.rb +13 -0
  56. metadata +62 -4
data/.gitignore CHANGED
@@ -2,7 +2,6 @@
2
2
  **/*.log
3
3
  spec/**/*.log
4
4
  *.gem
5
- *.gemspec
6
5
  pkg
7
6
  rdoc
8
7
  coverage
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'rake/rdoctask'
3
3
  require 'rake/gempackagetask'
4
4
  require 'rake/contrib/sshpublisher'
5
+ gem 'gem_version', '>=0.0.6'
5
6
  require 'gem_version'
6
7
 
7
8
  spec = Gem::Specification.new do |s|
@@ -67,6 +68,13 @@ namespace :spec do
67
68
  t.spec_opts = ['--options', 'spec/spec.opts']
68
69
  t.rcov = false
69
70
  end
71
+ Spec::Rake::SpecTask.new(:forms3) do |t|
72
+ t.spec_files = FileList['spec/rails3/spec/integrations/*_spec.rb']
73
+ t.libs << 'lib' << 'spec/rails3/spec'
74
+ t.spec_opts = ['--options', 'spec/spec.opts']
75
+ t.rcov = false
76
+ ENV['BUNDLE_GEMFILE'] = File.expand_path(File.join(File.dirname(__FILE__), 'spec', 'rails3', 'Gemfile'))
77
+ end
70
78
  # Spec::Rake::SpecTask.new(:associations) do |t|
71
79
  # t.spec_files = FileList['spec/active_record/associations_spec.rb']
72
80
  # t.libs << 'lib' << 'spec/active_record'
@@ -92,7 +100,9 @@ task :gemspec do
92
100
  f.write spec.to_ruby
93
101
  end
94
102
  GemVersion.increment_version
95
- GemVersion.commit_and_push
103
+ GemVersion.commit_and_push do |git|
104
+ git.add("#{spec.name}.gemspec")
105
+ end
96
106
  end
97
107
 
98
108
  Rake::GemPackageTask.new(spec) do |p|
@@ -72,17 +72,19 @@ if defined?(ActionView::Base)
72
72
  end
73
73
 
74
74
  #initialize record_name, method, self
75
- def to_tag_with_enumerated_attribute(options={})
76
- #look for an enum
77
- if (column_type == :string &&
78
- self.object.class.respond_to?(:has_enumerated_attribute?) &&
79
- self.object.class.has_enumerated_attribute?(method_name.to_sym))
80
- to_enum_select_tag(options)
81
- else
82
- to_tag_without_enumerated_attribute(options)
83
- end
75
+ if respond_to?(:to_tag)
76
+ def to_tag_with_enumerated_attribute(options={})
77
+ #look for an enum
78
+ if (column_type == :string &&
79
+ self.object.class.respond_to?(:has_enumerated_attribute?) &&
80
+ self.object.class.has_enumerated_attribute?(method_name.to_sym))
81
+ to_enum_select_tag(options)
82
+ else
83
+ to_tag_without_enumerated_attribute(options)
84
+ end
85
+ end
86
+ alias_method_chain :to_tag, :enumerated_attribute
84
87
  end
85
- alias_method_chain :to_tag, :enumerated_attribute
86
88
  end
87
89
 
88
90
  class FormBuilder
@@ -1,7 +1,7 @@
1
1
  # Be sure to restart your server when you modify this file
2
2
 
3
3
  # Specifies gem version of Rails to use when vendor/rails is not present
4
- RAILS_GEM_VERSION = ['>=2.3.0', '< 3.0.0'] unless defined? RAILS_GEM_VERSION
4
+ RAILS_GEM_VERSION = '< 2.4.0' unless defined? RAILS_GEM_VERSION
5
5
 
6
6
  # Bootstrap the Rails environment, frameworks, and default configuration
7
7
  require File.join(File.dirname(__FILE__), 'boot')
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper.rb'))
2
2
 
3
3
  shared_examples_for "enum_select form" do
4
4
  it "should have select boxes for gender, status and degree initially set blank" do
@@ -0,0 +1,30 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '3.0.0.beta3'
4
+
5
+ # Bundle edge Rails instead:
6
+ # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
+
8
+ gem 'sqlite3-ruby', :require => 'sqlite3'
9
+
10
+ gem 'meta_programming', '0.2.0'
11
+ gem 'rspec', '>=2.0.0'
12
+ gem 'rspec-rails'
13
+
14
+ # Use unicorn as the web server
15
+ # gem 'unicorn'
16
+
17
+ # Deploy with Capistrano
18
+ # gem 'capistrano'
19
+
20
+ # Bundle the extra gems:
21
+ # gem 'bj'
22
+ # gem 'nokogiri', '1.4.1'
23
+ # gem 'sqlite3-ruby', :require => 'sqlite3'
24
+ # gem 'aws-s3', :require => 'aws/s3'
25
+
26
+ # Bundle gems for certain environments:
27
+ # gem 'rspec', :group => :test
28
+ # group :test do
29
+ # gem 'webrat'
30
+ # end
@@ -0,0 +1,244 @@
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>rails 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 if it's installed when started with <tt>rails server</tt>, otherwise
40
+ Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
41
+ with a variety of other web servers.
42
+
43
+ Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
44
+ suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
45
+ getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
46
+ More info at: http://mongrel.rubyforge.org
47
+
48
+ Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
49
+ Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
50
+ FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
51
+
52
+ == Apache .htaccess example for FCGI/CGI
53
+
54
+ # General Apache options
55
+ AddHandler fastcgi-script .fcgi
56
+ AddHandler cgi-script .cgi
57
+ Options +FollowSymLinks +ExecCGI
58
+
59
+ # If you don't want Rails to look in certain directories,
60
+ # use the following rewrite rules so that Apache won't rewrite certain requests
61
+ #
62
+ # Example:
63
+ # RewriteCond %{REQUEST_URI} ^/notrails.*
64
+ # RewriteRule .* - [L]
65
+
66
+ # Redirect all requests not available on the filesystem to Rails
67
+ # By default the cgi dispatcher is used which is very slow
68
+ #
69
+ # For better performance replace the dispatcher with the fastcgi one
70
+ #
71
+ # Example:
72
+ # RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
73
+ RewriteEngine On
74
+
75
+ # If your Rails application is accessed via an Alias directive,
76
+ # then you MUST also set the RewriteBase in this htaccess file.
77
+ #
78
+ # Example:
79
+ # Alias /myrailsapp /path/to/myrailsapp/public
80
+ # RewriteBase /myrailsapp
81
+
82
+ RewriteRule ^$ index.html [QSA]
83
+ RewriteRule ^([^.]+)$ $1.html [QSA]
84
+ RewriteCond %{REQUEST_FILENAME} !-f
85
+ RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
86
+
87
+ # In case Rails experiences terminal errors
88
+ # Instead of displaying this message you can supply a file here which will be rendered instead
89
+ #
90
+ # Example:
91
+ # ErrorDocument 500 /500.html
92
+
93
+ ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
94
+
95
+
96
+ == Debugging Rails
97
+
98
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
99
+ will help you debug it and get it back on the rails.
100
+
101
+ First area to check is the application log files. Have "tail -f" commands running
102
+ on the server.log and development.log. Rails will automatically display debugging
103
+ and runtime information to these files. Debugging info will also be shown in the
104
+ browser on requests from 127.0.0.1.
105
+
106
+ You can also log your own messages directly into the log file from your code using
107
+ the Ruby logger class from inside your controllers. Example:
108
+
109
+ class WeblogController < ActionController::Base
110
+ def destroy
111
+ @weblog = Weblog.find(params[:id])
112
+ @weblog.destroy
113
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
114
+ end
115
+ end
116
+
117
+ The result will be a message in your log file along the lines of:
118
+
119
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
120
+
121
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
122
+
123
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
124
+
125
+ * The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
126
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
127
+
128
+ These two online (and free) books will bring you up to speed on the Ruby language
129
+ and also on programming in general.
130
+
131
+
132
+ == Debugger
133
+
134
+ Debugger support is available through the debugger command when you start your Mongrel or
135
+ Webrick server with --debugger. This means that you can break out of execution at any point
136
+ in the code, investigate and change the model, AND then resume execution!
137
+ You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
138
+ Example:
139
+
140
+ class WeblogController < ActionController::Base
141
+ def index
142
+ @posts = Post.find(:all)
143
+ debugger
144
+ end
145
+ end
146
+
147
+ So the controller will accept the action, run the first line, then present you
148
+ with a IRB prompt in the server window. Here you can do things like:
149
+
150
+ >> @posts.inspect
151
+ => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
152
+ #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
153
+ >> @posts.first.title = "hello from a debugger"
154
+ => "hello from a debugger"
155
+
156
+ ...and even better is that you can examine how your runtime objects actually work:
157
+
158
+ >> f = @posts.first
159
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
160
+ >> f.
161
+ Display all 152 possibilities? (y or n)
162
+
163
+ Finally, when you're ready to resume execution, you enter "cont"
164
+
165
+
166
+ == Console
167
+
168
+ You can interact with the domain model by starting the console through <tt>rails console</tt>.
169
+ Here you'll have all parts of the application configured, just like it is when the
170
+ application is running. You can inspect domain models, change values, and save to the
171
+ database. Starting the script without arguments will launch it in the development environment.
172
+ Passing an argument will specify a different environment, like <tt>rails console production</tt>.
173
+
174
+ To reload your controllers and models after launching the console run <tt>reload!</tt>
175
+
176
+ == dbconsole
177
+
178
+ You can go to the command line of your database directly through <tt>rails dbconsole</tt>.
179
+ You would be connected to the database with the credentials defined in database.yml.
180
+ Starting the script without arguments will connect you to the development database. Passing an
181
+ argument will connect you to a different database, like <tt>rails dbconsole production</tt>.
182
+ Currently works for mysql, postgresql and sqlite.
183
+
184
+ == Description of Contents
185
+
186
+ app
187
+ Holds all the code that's specific to this particular application.
188
+
189
+ app/controllers
190
+ Holds controllers that should be named like weblogs_controller.rb for
191
+ automated URL mapping. All controllers should descend from ApplicationController
192
+ which itself descends from ActionController::Base.
193
+
194
+ app/models
195
+ Holds models that should be named like post.rb.
196
+ Most models will descend from ActiveRecord::Base.
197
+
198
+ app/views
199
+ Holds the template files for the view that should be named like
200
+ weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
201
+ syntax.
202
+
203
+ app/views/layouts
204
+ Holds the template files for layouts to be used with views. This models the common
205
+ header/footer method of wrapping views. In your views, define a layout using the
206
+ <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
207
+ call <% yield %> to render the view using this layout.
208
+
209
+ app/helpers
210
+ Holds view helpers that should be named like weblogs_helper.rb. These are generated
211
+ for you automatically when using rails generate for controllers. Helpers can be used to
212
+ wrap functionality for your views into methods.
213
+
214
+ config
215
+ Configuration files for the Rails environment, the routing map, the database, and other dependencies.
216
+
217
+ db
218
+ Contains the database schema in schema.rb. db/migrate contains all
219
+ the sequence of Migrations for your schema.
220
+
221
+ doc
222
+ This directory is where your application documentation will be stored when generated
223
+ using <tt>rake doc:app</tt>
224
+
225
+ lib
226
+ Application specific libraries. Basically, any kind of custom code that doesn't
227
+ belong under controllers, models, or helpers. This directory is in the load path.
228
+
229
+ public
230
+ The directory available for the web server. Contains subdirectories for images, stylesheets,
231
+ and javascripts. Also contains the dispatchers and the default HTML files. This should be
232
+ set as the DOCUMENT_ROOT of your web server.
233
+
234
+ script
235
+ Helper scripts for automation and generation.
236
+
237
+ test
238
+ Unit and functional tests along with fixtures. When using the rails generate command, template
239
+ test files will be generated for you and placed in this directory.
240
+
241
+ vendor
242
+ External libraries that the application depends on. Also includes the plugins subdirectory.
243
+ If the app has frozen rails, those gems also go here, under vendor/rails/.
244
+ This directory is in the load path.
@@ -0,0 +1,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ Rails::Application.load_tasks
@@ -0,0 +1,10 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
7
+
8
+ # Scrub sensitive parameters from your log
9
+ # filter_parameter_logging :password
10
+ end
@@ -0,0 +1,38 @@
1
+ class FormTestController < ApplicationController
2
+
3
+ def index
4
+ end
5
+
6
+ #ActionView::Helpers:ActiveRecordHelper
7
+ def form
8
+ @user = User.new(params[:user])
9
+ return if request.get?
10
+
11
+ return unless @user.save
12
+ redirect_to :action=>:index
13
+ end
14
+
15
+ #ActionView::Helpers::FormHelper
16
+ def form_for
17
+ @user = User.new(params[:user])
18
+ return if request.get?
19
+
20
+ return unless @user.save
21
+ redirect_to :action=>:index
22
+ end
23
+
24
+ #ActionView::Helpers::FormTagHelper
25
+ def form_tag
26
+ @user = User.new(params[:user])
27
+ return if request.get?
28
+
29
+ return unless @user.save
30
+ redirect_to :action=>:index
31
+ end
32
+
33
+ #ActionView::Helpers::FormOptionsHelper
34
+ # def select
35
+ #
36
+ # end
37
+
38
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,2 @@
1
+ module FormTestHelper
2
+ end
@@ -0,0 +1,9 @@
1
+ require 'enumerated_attribute'
2
+ class User < ActiveRecord::Base
3
+ validates_presence_of :first_name, :gender, :age, :status, :degree
4
+ validates_numericality_of :age
5
+
6
+ enum_attr :gender, %w(male female)
7
+ enum_attr :status, %w(single married divorced widowed)
8
+ enum_attr :degree, %w(^none high_school college graduate)
9
+ end
@@ -0,0 +1 @@
1
+ <%= form 'user', :action=>:form, :submit_value=>'Save' %>