simple_form_class 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. data/.gitignore +28 -0
  2. data/.travis.yml +19 -0
  3. data/Gemfile +27 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +31 -0
  6. data/Rakefile +45 -0
  7. data/lib/simple_form_class.rb +10 -0
  8. data/lib/simple_form_class/base.rb +212 -0
  9. data/lib/simple_form_class/version.rb +3 -0
  10. data/simple_form_class.gemspec +33 -0
  11. data/test/.gitkeep +0 -0
  12. data/test/dummy/.gitignore +15 -0
  13. data/test/dummy/Gemfile +38 -0
  14. data/test/dummy/README.rdoc +261 -0
  15. data/test/dummy/Rakefile +7 -0
  16. data/test/dummy/app/assets/images/rails.png +0 -0
  17. data/test/dummy/app/assets/javascripts/application.js +15 -0
  18. data/test/dummy/app/assets/javascripts/orders.js.coffee +3 -0
  19. data/test/dummy/app/assets/javascripts/products.js.coffee +3 -0
  20. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  21. data/test/dummy/app/assets/stylesheets/orders.css.scss +3 -0
  22. data/test/dummy/app/assets/stylesheets/products.css.scss +3 -0
  23. data/test/dummy/app/assets/stylesheets/scaffolds.css.scss +69 -0
  24. data/test/dummy/app/controllers/application_controller.rb +3 -0
  25. data/test/dummy/app/controllers/orders_controller.rb +83 -0
  26. data/test/dummy/app/controllers/products_controller.rb +83 -0
  27. data/test/dummy/app/helpers/application_helper.rb +2 -0
  28. data/test/dummy/app/helpers/orders_helper.rb +2 -0
  29. data/test/dummy/app/helpers/products_helper.rb +2 -0
  30. data/test/dummy/app/mailers/.gitkeep +0 -0
  31. data/test/dummy/app/models/.gitkeep +0 -0
  32. data/test/dummy/app/models/order.rb +2 -0
  33. data/test/dummy/app/models/product.rb +2 -0
  34. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  35. data/test/dummy/app/views/orders/_form.html.erb +29 -0
  36. data/test/dummy/app/views/orders/edit.html.erb +6 -0
  37. data/test/dummy/app/views/orders/index.html.erb +27 -0
  38. data/test/dummy/app/views/orders/new.html.erb +5 -0
  39. data/test/dummy/app/views/orders/show.html.erb +20 -0
  40. data/test/dummy/app/views/products/_form.html.erb +25 -0
  41. data/test/dummy/app/views/products/edit.html.erb +6 -0
  42. data/test/dummy/app/views/products/index.html.erb +25 -0
  43. data/test/dummy/app/views/products/new.html.erb +5 -0
  44. data/test/dummy/app/views/products/show.html.erb +15 -0
  45. data/test/dummy/config.ru +4 -0
  46. data/test/dummy/config/application.rb +64 -0
  47. data/test/dummy/config/boot.rb +6 -0
  48. data/test/dummy/config/database.yml +25 -0
  49. data/test/dummy/config/environment.rb +5 -0
  50. data/test/dummy/config/environments/development.rb +24 -0
  51. data/test/dummy/config/environments/production.rb +55 -0
  52. data/test/dummy/config/environments/test.rb +25 -0
  53. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  54. data/test/dummy/config/initializers/inflections.rb +15 -0
  55. data/test/dummy/config/initializers/mime_types.rb +5 -0
  56. data/test/dummy/config/initializers/secret_token.rb +7 -0
  57. data/test/dummy/config/initializers/session_store.rb +8 -0
  58. data/test/dummy/config/locales/en.yml +5 -0
  59. data/test/dummy/config/routes.rb +64 -0
  60. data/test/dummy/db/migrate/20130420130732_create_products.rb +10 -0
  61. data/test/dummy/db/migrate/20130420130801_create_orders.rb +11 -0
  62. data/test/dummy/db/schema.rb +31 -0
  63. data/test/dummy/db/seeds.rb +7 -0
  64. data/test/dummy/lib/assets/.gitkeep +0 -0
  65. data/test/dummy/lib/tasks/.gitkeep +0 -0
  66. data/test/dummy/log/.gitkeep +0 -0
  67. data/test/dummy/public/404.html +26 -0
  68. data/test/dummy/public/422.html +26 -0
  69. data/test/dummy/public/500.html +25 -0
  70. data/test/dummy/public/favicon.ico +0 -0
  71. data/test/dummy/public/index.html +241 -0
  72. data/test/dummy/public/robots.txt +5 -0
  73. data/test/dummy/script/rails +6 -0
  74. data/test/dummy/test/fixtures/.gitkeep +0 -0
  75. data/test/dummy/test/fixtures/orders.yml +11 -0
  76. data/test/dummy/test/fixtures/products.yml +9 -0
  77. data/test/dummy/test/functional/.gitkeep +0 -0
  78. data/test/dummy/test/functional/orders_controller_test.rb +49 -0
  79. data/test/dummy/test/functional/products_controller_test.rb +49 -0
  80. data/test/dummy/test/integration/.gitkeep +0 -0
  81. data/test/dummy/test/performance/browsing_test.rb +12 -0
  82. data/test/dummy/test/test_helper.rb +13 -0
  83. data/test/dummy/test/unit/.gitkeep +0 -0
  84. data/test/dummy/test/unit/helpers/orders_helper_test.rb +4 -0
  85. data/test/dummy/test/unit/helpers/products_helper_test.rb +4 -0
  86. data/test/dummy/test/unit/order_test.rb +7 -0
  87. data/test/dummy/test/unit/product_test.rb +7 -0
  88. data/test/dummy/vendor/assets/javascripts/.gitkeep +0 -0
  89. data/test/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  90. data/test/dummy/vendor/plugins/.gitkeep +0 -0
  91. data/test/support/dummy_app.rb +86 -0
  92. data/test/test_helper.rb +66 -0
  93. data/test/unit/base_test.rb +210 -0
  94. metadata +405 -0
@@ -0,0 +1,83 @@
1
+ class ProductsController < ApplicationController
2
+ # GET /products
3
+ # GET /products.json
4
+ def index
5
+ @products = Product.all
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.json { render json: @products }
10
+ end
11
+ end
12
+
13
+ # GET /products/1
14
+ # GET /products/1.json
15
+ def show
16
+ @product = Product.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.json { render json: @product }
21
+ end
22
+ end
23
+
24
+ # GET /products/new
25
+ # GET /products/new.json
26
+ def new
27
+ @product = Product.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.json { render json: @product }
32
+ end
33
+ end
34
+
35
+ # GET /products/1/edit
36
+ def edit
37
+ @product = Product.find(params[:id])
38
+ end
39
+
40
+ # POST /products
41
+ # POST /products.json
42
+ def create
43
+ @product = Product.new(params[:product])
44
+
45
+ respond_to do |format|
46
+ if @product.save
47
+ format.html { redirect_to @product, notice: 'Product was successfully created.' }
48
+ format.json { render json: @product, status: :created, location: @product }
49
+ else
50
+ format.html { render action: "new" }
51
+ format.json { render json: @product.errors, status: :unprocessable_entity }
52
+ end
53
+ end
54
+ end
55
+
56
+ # PUT /products/1
57
+ # PUT /products/1.json
58
+ def update
59
+ @product = Product.find(params[:id])
60
+
61
+ respond_to do |format|
62
+ if @product.update_attributes(params[:product])
63
+ format.html { redirect_to @product, notice: 'Product was successfully updated.' }
64
+ format.json { head :no_content }
65
+ else
66
+ format.html { render action: "edit" }
67
+ format.json { render json: @product.errors, status: :unprocessable_entity }
68
+ end
69
+ end
70
+ end
71
+
72
+ # DELETE /products/1
73
+ # DELETE /products/1.json
74
+ def destroy
75
+ @product = Product.find(params[:id])
76
+ @product.destroy
77
+
78
+ respond_to do |format|
79
+ format.html { redirect_to products_url }
80
+ format.json { head :no_content }
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module OrdersHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module ProductsHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ class Order < ActiveRecord::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ class Product < ActiveRecord::Base
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", :media => "all" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,29 @@
1
+ <%= form_for(@order) do |f| %>
2
+ <% if @order.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@order.errors.count, "error") %> prohibited this order from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @order.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :product_id %><br />
16
+ <%= f.number_field :product_id %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :order_number %><br />
20
+ <%= f.text_field :order_number %>
21
+ </div>
22
+ <div class="field">
23
+ <%= f.label :price %><br />
24
+ <%= f.number_field :price %>
25
+ </div>
26
+ <div class="actions">
27
+ <%= f.submit %>
28
+ </div>
29
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing order</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @order %> |
6
+ <%= link_to 'Back', orders_path %>
@@ -0,0 +1,27 @@
1
+ <h1>Listing orders</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Product</th>
6
+ <th>Order number</th>
7
+ <th>Price</th>
8
+ <th></th>
9
+ <th></th>
10
+ <th></th>
11
+ </tr>
12
+
13
+ <% @orders.each do |order| %>
14
+ <tr>
15
+ <td><%= order.product_id %></td>
16
+ <td><%= order.order_number %></td>
17
+ <td><%= order.price %></td>
18
+ <td><%= link_to 'Show', order %></td>
19
+ <td><%= link_to 'Edit', edit_order_path(order) %></td>
20
+ <td><%= link_to 'Destroy', order, method: :delete, data: { confirm: 'Are you sure?' } %></td>
21
+ </tr>
22
+ <% end %>
23
+ </table>
24
+
25
+ <br />
26
+
27
+ <%= link_to 'New Order', new_order_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New order</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', orders_path %>
@@ -0,0 +1,20 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Product:</b>
5
+ <%= @order.product_id %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Order number:</b>
10
+ <%= @order.order_number %>
11
+ </p>
12
+
13
+ <p>
14
+ <b>Price:</b>
15
+ <%= @order.price %>
16
+ </p>
17
+
18
+
19
+ <%= link_to 'Edit', edit_order_path(@order) %> |
20
+ <%= link_to 'Back', orders_path %>
@@ -0,0 +1,25 @@
1
+ <%= form_for(@product) do |f| %>
2
+ <% if @product.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @product.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :name %><br />
16
+ <%= f.text_field :name %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :price %><br />
20
+ <%= f.number_field :price %>
21
+ </div>
22
+ <div class="actions">
23
+ <%= f.submit %>
24
+ </div>
25
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing product</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @product %> |
6
+ <%= link_to 'Back', products_path %>
@@ -0,0 +1,25 @@
1
+ <h1>Listing products</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Name</th>
6
+ <th>Price</th>
7
+ <th></th>
8
+ <th></th>
9
+ <th></th>
10
+ </tr>
11
+
12
+ <% @products.each do |product| %>
13
+ <tr>
14
+ <td><%= product.name %></td>
15
+ <td><%= product.price %></td>
16
+ <td><%= link_to 'Show', product %></td>
17
+ <td><%= link_to 'Edit', edit_product_path(product) %></td>
18
+ <td><%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %></td>
19
+ </tr>
20
+ <% end %>
21
+ </table>
22
+
23
+ <br />
24
+
25
+ <%= link_to 'New Product', new_product_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New product</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', products_path %>
@@ -0,0 +1,15 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Name:</b>
5
+ <%= @product.name %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Price:</b>
10
+ <%= @product.price %>
11
+ </p>
12
+
13
+
14
+ <%= link_to 'Edit', edit_product_path(@product) %> |
15
+ <%= link_to 'Back', products_path %>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,64 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+ require 'strong_parameters'
5
+ require 'simple_form_class'
6
+
7
+ module Dummy
8
+ class Application < Rails::Application
9
+ # Settings in config/environments/* take precedence over those specified here.
10
+ # Application configuration should go into files in config/initializers
11
+ # -- all .rb files in that directory are automatically loaded.
12
+
13
+ # Custom directories with classes and modules you want to be autoloadable.
14
+ # config.autoload_paths += %W(#{config.root}/extras)
15
+
16
+ # Only load the plugins named here, in the order given (default is alphabetical).
17
+ # :all can be used as a placeholder for all plugins not explicitly named.
18
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
19
+
20
+ # Activate observers that should always be running.
21
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
22
+
23
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
24
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
25
+ # config.time_zone = 'Central Time (US & Canada)'
26
+
27
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
28
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
29
+ # config.i18n.default_locale = :de
30
+
31
+ # Configure the default encoding used in templates for Ruby 1.9.
32
+ config.encoding = "utf-8"
33
+
34
+ # Configure sensitive parameters which will be filtered from the log file.
35
+ config.filter_parameters += [:password]
36
+
37
+ # Enable escaping HTML in JSON.
38
+ config.active_support.escape_html_entities_in_json = true
39
+
40
+ # Use SQL instead of Active Record's schema dumper when creating the database.
41
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
42
+ # like if you have constraints or database-specific column types
43
+ # config.active_record.schema_format = :sql
44
+
45
+ # Enforce whitelist mode for mass assignment.
46
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
47
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
48
+ # parameters by using an attr_accessible or attr_protected declaration.
49
+ # config.active_record.whitelist_attributes = true
50
+
51
+ # Enable the asset pipeline
52
+ # config.assets.enabled = true
53
+
54
+ # Version of your assets, change this if you want to expire all your assets
55
+ # config.assets.version = '1.0'
56
+
57
+ # Tell Action Mailer not to deliver emails to the real world.
58
+ # The :test delivery method accumulates sent emails in the
59
+ # ActionMailer::Base.deliveries array.
60
+ config.action_mailer.delivery_method = :test
61
+ end
62
+ end
63
+
64
+ ActiveRecord::Migration.verbose = false
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,24 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+ end
@@ -0,0 +1,55 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+
11
+ # Defaults to nil and saved in location specified by config.assets.prefix
12
+ # config.assets.manifest = YOUR_PATH
13
+
14
+ # Specifies the header that your server uses for sending files
15
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
16
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
17
+
18
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
19
+ # config.force_ssl = true
20
+
21
+ # See everything in the log (default is :info)
22
+ # config.log_level = :debug
23
+
24
+ # Prepend all log lines with the following tags
25
+ # config.log_tags = [ :subdomain, :uuid ]
26
+
27
+ # Use a different logger for distributed setups
28
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
29
+
30
+ # Use a different cache store in production
31
+ # config.cache_store = :mem_cache_store
32
+
33
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
34
+ # config.action_controller.asset_host = "http://assets.example.com"
35
+
36
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
37
+ # config.assets.precompile += %w( search.js )
38
+
39
+ # Disable delivery errors, bad email addresses will be ignored
40
+ # config.action_mailer.raise_delivery_errors = false
41
+
42
+ # Enable threaded mode
43
+ # config.threadsafe!
44
+
45
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
46
+ # the I18n.default_locale when a translation can not be found)
47
+ config.i18n.fallbacks = true
48
+
49
+ # Send deprecation notices to registered listeners
50
+ config.active_support.deprecation = :notify
51
+
52
+ # Log the query plan for queries taking more than this (works
53
+ # with SQLite, MySQL, and PostgreSQL)
54
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
55
+ end