simple_form 0.5 → 1.0.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.

Potentially problematic release.


This version of simple_form might be problematic. Click here for more details.

Files changed (48) hide show
  1. data/README.rdoc +339 -6
  2. data/generators/simple_form_install/USAGE +3 -0
  3. data/generators/simple_form_install/simple_form_install_generator.rb +19 -0
  4. data/generators/simple_form_install/templates/simple_form.rb +38 -0
  5. data/init.rb +1 -0
  6. data/lib/simple_form.rb +57 -1
  7. data/lib/simple_form/action_view_extensions/builder.rb +122 -0
  8. data/lib/simple_form/action_view_extensions/form_helper.rb +33 -0
  9. data/lib/simple_form/action_view_extensions/instance_tag.rb +37 -0
  10. data/lib/simple_form/components.rb +8 -0
  11. data/lib/simple_form/components/errors.rb +35 -0
  12. data/lib/simple_form/components/hints.rb +21 -0
  13. data/lib/simple_form/components/labels.rb +68 -0
  14. data/lib/simple_form/components/wrapper.rb +21 -0
  15. data/lib/simple_form/form_builder.rb +332 -0
  16. data/lib/simple_form/i18n_cache.rb +22 -0
  17. data/lib/simple_form/inputs.rb +12 -0
  18. data/lib/simple_form/inputs/base.rb +107 -0
  19. data/lib/simple_form/inputs/block_input.rb +13 -0
  20. data/lib/simple_form/inputs/collection_input.rb +58 -0
  21. data/lib/simple_form/inputs/date_time_input.rb +18 -0
  22. data/lib/simple_form/inputs/hidden_input.rb +11 -0
  23. data/lib/simple_form/inputs/mapping_input.rb +23 -0
  24. data/lib/simple_form/inputs/priority_input.rb +20 -0
  25. data/lib/simple_form/inputs/text_field_input.rb +16 -0
  26. data/lib/simple_form/locale/en.yml +14 -0
  27. data/lib/simple_form/map_type.rb +13 -0
  28. data/lib/simple_form/version.rb +3 -0
  29. data/test/action_view_extensions/builder_test.rb +172 -0
  30. data/test/action_view_extensions/form_helper_test.rb +50 -0
  31. data/test/components/error_test.rb +45 -0
  32. data/test/components/hint_test.rb +78 -0
  33. data/test/components/label_test.rb +170 -0
  34. data/test/form_builder_test.rb +550 -0
  35. data/test/inputs_test.rb +337 -0
  36. data/test/simple_form_test.rb +9 -0
  37. data/test/support/country_select/init.rb +1 -0
  38. data/test/support/country_select/install.rb +2 -0
  39. data/test/support/country_select/lib/country_select.rb +84 -0
  40. data/test/support/country_select/uninstall.rb +1 -0
  41. data/test/support/misc_helpers.rb +29 -0
  42. data/test/support/mock_controller.rb +11 -0
  43. data/test/support/mock_response.rb +14 -0
  44. data/test/support/models.rb +100 -0
  45. data/test/test_helper.rb +60 -0
  46. metadata +50 -10
  47. data/CHANGELOG +0 -27
  48. data/Rakefile +0 -17
@@ -0,0 +1,11 @@
1
+ class MockController
2
+ attr_accessor :action_name
3
+
4
+ def action_name
5
+ @action_name || "edit"
6
+ end
7
+
8
+ def url_for(*args)
9
+ "http://example.com"
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ class MockResponse
2
+
3
+ def initialize(test_case)
4
+ @test_case = test_case
5
+ end
6
+
7
+ def content_type
8
+ 'text/html'
9
+ end
10
+
11
+ def body
12
+ @test_case.send :output_buffer
13
+ end
14
+ end
@@ -0,0 +1,100 @@
1
+ require 'ostruct'
2
+
3
+ Column = Struct.new(:name, :type, :limit)
4
+ Association = Struct.new(:klass, :name, :macro, :options)
5
+
6
+ class Company < Struct.new(:id, :name)
7
+ def self.all(options={})
8
+ all = (1..3).map{|i| Company.new(i, "Company #{i}")}
9
+ return [all.first] if options[:conditions].present?
10
+ return [all.last] if options[:order].present?
11
+ return all[0..1] if options[:include].present?
12
+ return all[1..2] if options[:joins].present?
13
+ all
14
+ end
15
+
16
+ def self.merge_conditions(a, b)
17
+ (a || {}).merge(b || {})
18
+ end
19
+
20
+ def new_record?
21
+ false
22
+ end
23
+ end
24
+
25
+ class Tag < Company
26
+ def self.all(options={})
27
+ (1..3).map{|i| Tag.new(i, "Tag #{i}")}
28
+ end
29
+ end
30
+
31
+ class User < OpenStruct
32
+ # Get rid of deprecation warnings
33
+ undef_method :id
34
+
35
+ def new_record!
36
+ @new_record = true
37
+ end
38
+
39
+ def new_record?
40
+ @new_record || false
41
+ end
42
+
43
+ def company_attributes=(foo)
44
+ end
45
+
46
+ def column_for_attribute(attribute)
47
+ column_type, limit = case attribute.to_sym
48
+ when :name, :status, :password then [:string, 100]
49
+ when :description then :text
50
+ when :age then :integer
51
+ when :credit_limit then [:decimal, 15]
52
+ when :active then :boolean
53
+ when :born_at then :date
54
+ when :delivery_time then :time
55
+ when :created_at then :datetime
56
+ when :updated_at then :timestamp
57
+ end
58
+ Column.new(attribute, column_type, limit)
59
+ end
60
+
61
+ def self.human_attribute_name(attribute)
62
+ case attribute
63
+ when 'name'
64
+ 'Super User Name!'
65
+ when 'description'
66
+ 'User Description!'
67
+ when 'company'
68
+ 'Company Human Name!'
69
+ else
70
+ attribute.humanize
71
+ end
72
+ end
73
+
74
+ def self.human_name
75
+ "User"
76
+ end
77
+
78
+ def self.reflect_on_association(association)
79
+ case association
80
+ when :company
81
+ Association.new(Company, association, :belongs_to, {})
82
+ when :tags
83
+ Association.new(Tag, association, :has_many, {})
84
+ when :first_company
85
+ Association.new(Company, association, :has_one, {})
86
+ when :special_company
87
+ Association.new(Company, association, :belongs_to, { :conditions => { :id => 1 } })
88
+ end
89
+ end
90
+
91
+ def errors
92
+ @errors ||= {
93
+ :name => "can't be blank",
94
+ :description => "must be longer than 15 characters",
95
+ :age => ["is not a number", "must be greater than 18"],
96
+ :company => "company must be present",
97
+ :company_id => "must be valid"
98
+ }
99
+ end
100
+ end
@@ -0,0 +1,60 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ require 'action_controller'
5
+ require 'action_view/test_case'
6
+
7
+ begin
8
+ require 'ruby-debug'
9
+ rescue LoadError
10
+ end
11
+
12
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib', 'simple_form')
13
+ require 'simple_form'
14
+
15
+ Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
16
+ I18n.default_locale = :en
17
+
18
+ $:.unshift "#{File.dirname(__FILE__)}/support/country_select/lib"
19
+ require 'country_select'
20
+
21
+ class SimpleForm::FormBuilder
22
+ attr_accessor :attribute_name, :column, :reflection, :input_type, :options
23
+ end
24
+
25
+ class ActionView::TestCase
26
+ include MiscHelpers
27
+
28
+ tests SimpleForm::ActionViewExtensions::FormHelper
29
+
30
+ setup :set_controller
31
+ setup :set_response
32
+ setup :setup_new_user
33
+
34
+ def set_controller
35
+ @controller = MockController.new
36
+ end
37
+
38
+ def set_response
39
+ @response = MockResponse.new(self)
40
+ end
41
+
42
+ def setup_new_user(options={})
43
+ @user = User.new({
44
+ :id => 1,
45
+ :name => 'New in Simple Form!',
46
+ :description => 'Hello!',
47
+ :created_at => Time.now
48
+ }.merge(options))
49
+ end
50
+
51
+ def protect_against_forgery?
52
+ false
53
+ end
54
+
55
+ def user_path(*args)
56
+ '/users'
57
+ end
58
+ alias :users_path :user_path
59
+ alias :super_user_path :user_path
60
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.5"
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Jos\xC3\xA9 Valim"
@@ -10,11 +10,11 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-12-24 00:00:00 +01:00
13
+ date: 2010-02-06 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
17
- description: Simple easy contact form for Rails with I18n, validations, attachments and request information.
17
+ description: Forms made easy!
18
18
  email: contact@plataformatec.com.br
19
19
  executables: []
20
20
 
@@ -23,12 +23,36 @@ extensions: []
23
23
  extra_rdoc_files:
24
24
  - README.rdoc
25
25
  files:
26
- - CHANGELOG
27
- - README.rdoc
28
- - Rakefile
26
+ - generators/simple_form_install/USAGE
27
+ - generators/simple_form_install/simple_form_install_generator.rb
28
+ - generators/simple_form_install/templates/simple_form.rb
29
+ - init.rb
29
30
  - lib/simple_form.rb
31
+ - lib/simple_form/action_view_extensions/builder.rb
32
+ - lib/simple_form/action_view_extensions/form_helper.rb
33
+ - lib/simple_form/action_view_extensions/instance_tag.rb
34
+ - lib/simple_form/components.rb
35
+ - lib/simple_form/components/errors.rb
36
+ - lib/simple_form/components/hints.rb
37
+ - lib/simple_form/components/labels.rb
38
+ - lib/simple_form/components/wrapper.rb
39
+ - lib/simple_form/form_builder.rb
40
+ - lib/simple_form/i18n_cache.rb
41
+ - lib/simple_form/inputs.rb
42
+ - lib/simple_form/inputs/base.rb
43
+ - lib/simple_form/inputs/block_input.rb
44
+ - lib/simple_form/inputs/collection_input.rb
45
+ - lib/simple_form/inputs/date_time_input.rb
46
+ - lib/simple_form/inputs/hidden_input.rb
47
+ - lib/simple_form/inputs/mapping_input.rb
48
+ - lib/simple_form/inputs/priority_input.rb
49
+ - lib/simple_form/inputs/text_field_input.rb
50
+ - lib/simple_form/locale/en.yml
51
+ - lib/simple_form/map_type.rb
52
+ - lib/simple_form/version.rb
53
+ - README.rdoc
30
54
  has_rdoc: true
31
- homepage: http://github.com/josevalim/simple_form
55
+ homepage: http://github.com/plataformatec/simple_form
32
56
  licenses: []
33
57
 
34
58
  post_install_message:
@@ -54,6 +78,22 @@ rubyforge_project:
54
78
  rubygems_version: 1.3.5
55
79
  signing_key:
56
80
  specification_version: 3
57
- summary: Simple easy contact form for Rails with I18n, validations, attachments and request information.
58
- test_files: []
59
-
81
+ summary: Forms made easy!
82
+ test_files:
83
+ - test/action_view_extensions/builder_test.rb
84
+ - test/action_view_extensions/form_helper_test.rb
85
+ - test/components/error_test.rb
86
+ - test/components/hint_test.rb
87
+ - test/components/label_test.rb
88
+ - test/form_builder_test.rb
89
+ - test/inputs_test.rb
90
+ - test/simple_form_test.rb
91
+ - test/support/country_select/init.rb
92
+ - test/support/country_select/install.rb
93
+ - test/support/country_select/lib/country_select.rb
94
+ - test/support/country_select/uninstall.rb
95
+ - test/support/misc_helpers.rb
96
+ - test/support/mock_controller.rb
97
+ - test/support/mock_response.rb
98
+ - test/support/models.rb
99
+ - test/test_helper.rb
data/CHANGELOG DELETED
@@ -1,27 +0,0 @@
1
- * Version 0.5
2
-
3
- * SimpleForm is deprecated in favor of MailForm:
4
-
5
- http://github.com/plataformatec/mail_form/tree/v1.0
6
-
7
- For a Rails 2.3 version, please install:
8
-
9
- gem install mail_form --version=1.0
10
-
11
- * Version 0.4
12
-
13
- * Added support to template
14
-
15
- # Version 0.3
16
-
17
- * Added support to symbols on :sender, :subject and :recipients
18
- * Added support to symbols on :validate
19
-
20
- # Version 0.2
21
-
22
- * Added support to request objects and append DSL
23
- * Added support to :attachments (thanks to @andrewtimberlake)
24
-
25
- # Version 0.1
26
-
27
- * First release
data/Rakefile DELETED
@@ -1,17 +0,0 @@
1
- begin
2
- require 'jeweler'
3
- Jeweler::Tasks.new do |s|
4
- s.name = "simple_form"
5
- s.version = "0.5"
6
- s.summary = "Simple easy contact form for Rails with I18n, validations, attachments and request information."
7
- s.email = "contact@plataformatec.com.br"
8
- s.homepage = "http://github.com/josevalim/simple_form"
9
- s.description = "Simple easy contact form for Rails with I18n, validations, attachments and request information."
10
- s.authors = ['José Valim', 'Carlos Antônio']
11
- s.files = FileList["[A-Z]*", "init.rb", "install.rb", "{lib,views}/**/*"]
12
- end
13
-
14
- Jeweler::GemcutterTasks.new
15
- rescue LoadError
16
- puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
17
- end