formtastic 1.2.5 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.yardopts +1 -0
- data/CHANGELOG +279 -0
- data/Gemfile +3 -0
- data/README.textile +155 -172
- data/RELEASE_PROCESS +7 -0
- data/Rakefile +52 -0
- data/app/assets/stylesheets/formtastic.css +275 -0
- data/app/assets/stylesheets/formtastic_ie6.css +27 -0
- data/app/assets/stylesheets/formtastic_ie7.css +17 -0
- data/formtastic.gemspec +51 -0
- data/lib/formtastic.rb +21 -1960
- data/lib/formtastic/engine.rb +7 -0
- data/lib/formtastic/form_builder.rb +83 -0
- data/lib/formtastic/helpers.rb +16 -0
- data/lib/formtastic/helpers/buttons_helper.rb +277 -0
- data/lib/formtastic/helpers/errors_helper.rb +113 -0
- data/lib/formtastic/helpers/fieldset_wrapper.rb +75 -0
- data/lib/formtastic/helpers/file_column_detection.rb +16 -0
- data/lib/formtastic/helpers/form_helper.rb +198 -0
- data/lib/formtastic/helpers/input_helper.rb +366 -0
- data/lib/formtastic/helpers/inputs_helper.rb +392 -0
- data/lib/formtastic/helpers/reflection.rb +33 -0
- data/lib/formtastic/helpers/semantic_form_helper.rb +11 -0
- data/lib/formtastic/html_attributes.rb +21 -0
- data/lib/formtastic/i18n.rb +1 -0
- data/lib/formtastic/inputs.rb +31 -0
- data/lib/formtastic/inputs/base.rb +61 -0
- data/lib/formtastic/inputs/base/associations.rb +31 -0
- data/lib/formtastic/inputs/base/choices.rb +103 -0
- data/lib/formtastic/inputs/base/collections.rb +94 -0
- data/lib/formtastic/inputs/base/database.rb +17 -0
- data/lib/formtastic/inputs/base/errors.rb +58 -0
- data/lib/formtastic/inputs/base/fileish.rb +23 -0
- data/lib/formtastic/inputs/base/grouped_collections.rb +77 -0
- data/lib/formtastic/inputs/base/hints.rb +31 -0
- data/lib/formtastic/inputs/base/html.rb +52 -0
- data/lib/formtastic/inputs/base/labelling.rb +55 -0
- data/lib/formtastic/inputs/base/naming.rb +42 -0
- data/lib/formtastic/inputs/base/options.rb +18 -0
- data/lib/formtastic/inputs/base/stringish.rb +35 -0
- data/lib/formtastic/inputs/base/timeish.rb +128 -0
- data/lib/formtastic/inputs/base/validations.rb +166 -0
- data/lib/formtastic/inputs/base/wrapping.rb +40 -0
- data/lib/formtastic/inputs/boolean_input.rb +96 -0
- data/lib/formtastic/inputs/check_boxes_input.rb +179 -0
- data/lib/formtastic/inputs/country_input.rb +66 -0
- data/lib/formtastic/inputs/date_input.rb +14 -0
- data/lib/formtastic/inputs/datetime_input.rb +9 -0
- data/lib/formtastic/inputs/email_input.rb +40 -0
- data/lib/formtastic/inputs/file_input.rb +42 -0
- data/lib/formtastic/inputs/hidden_input.rb +66 -0
- data/lib/formtastic/inputs/number_input.rb +118 -0
- data/lib/formtastic/inputs/numeric_input.rb +21 -0
- data/lib/formtastic/inputs/password_input.rb +40 -0
- data/lib/formtastic/inputs/phone_input.rb +41 -0
- data/lib/formtastic/inputs/radio_input.rb +157 -0
- data/lib/formtastic/inputs/range_input.rb +119 -0
- data/lib/formtastic/inputs/search_input.rb +40 -0
- data/lib/formtastic/inputs/select_input.rb +210 -0
- data/lib/formtastic/inputs/string_input.rb +34 -0
- data/lib/formtastic/inputs/text_input.rb +47 -0
- data/lib/formtastic/inputs/time_input.rb +14 -0
- data/lib/formtastic/inputs/time_zone_input.rb +48 -0
- data/lib/formtastic/inputs/url_input.rb +40 -0
- data/lib/formtastic/localized_string.rb +105 -0
- data/lib/formtastic/railtie.rb +5 -7
- data/lib/formtastic/semantic_form_builder.rb +11 -0
- data/lib/formtastic/util.rb +6 -19
- data/lib/formtastic/version.rb +3 -0
- data/lib/generators/formtastic/install/install_generator.rb +28 -6
- data/lib/generators/templates/_form.html.erb +10 -4
- data/lib/generators/templates/_form.html.haml +8 -4
- data/lib/generators/templates/formtastic.rb +25 -32
- data/lib/locale/en.yml +1 -0
- data/lib/tasks/verify_rcov.rb +44 -0
- data/sample/basic_inputs.html +182 -0
- data/sample/config.ru +69 -0
- data/sample/index.html +14 -0
- data/spec/builder/custom_builder_spec.rb +109 -0
- data/spec/builder/error_proc_spec.rb +27 -0
- data/spec/builder/errors_spec.rb +193 -0
- data/spec/builder/semantic_fields_for_spec.rb +88 -0
- data/spec/helpers/buttons_helper_spec.rb +150 -0
- data/spec/helpers/commit_button_helper_spec.rb +470 -0
- data/spec/helpers/form_helper_spec.rb +135 -0
- data/spec/helpers/input_helper_spec.rb +837 -0
- data/spec/helpers/inputs_helper_spec.rb +562 -0
- data/spec/helpers/semantic_errors_helper_spec.rb +112 -0
- data/spec/i18n_spec.rb +199 -0
- data/spec/inputs/boolean_input_spec.rb +184 -0
- data/spec/inputs/check_boxes_input_spec.rb +375 -0
- data/spec/inputs/country_input_spec.rb +133 -0
- data/spec/inputs/custom_input_spec.rb +52 -0
- data/spec/inputs/date_input_spec.rb +110 -0
- data/spec/inputs/datetime_input_spec.rb +115 -0
- data/spec/inputs/email_input_spec.rb +55 -0
- data/spec/inputs/file_input_spec.rb +59 -0
- data/spec/inputs/hidden_input_spec.rb +120 -0
- data/spec/inputs/include_blank_spec.rb +70 -0
- data/spec/inputs/label_spec.rb +104 -0
- data/spec/inputs/number_input_spec.rb +487 -0
- data/spec/inputs/numeric_input_spec.rb +41 -0
- data/spec/inputs/password_input_spec.rb +69 -0
- data/spec/inputs/phone_input_spec.rb +55 -0
- data/spec/inputs/placeholder_spec.rb +71 -0
- data/spec/inputs/radio_input_spec.rb +234 -0
- data/spec/inputs/range_input_spec.rb +477 -0
- data/spec/inputs/search_input_spec.rb +55 -0
- data/spec/inputs/select_input_spec.rb +545 -0
- data/spec/inputs/string_input_spec.rb +163 -0
- data/spec/inputs/text_input_spec.rb +158 -0
- data/spec/inputs/time_input_spec.rb +155 -0
- data/spec/inputs/time_zone_input_spec.rb +87 -0
- data/spec/inputs/url_input_spec.rb +55 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +361 -0
- data/spec/support/custom_macros.rb +656 -0
- data/spec/support/deferred_garbage_collection.rb +21 -0
- data/spec/support/deprecation.rb +6 -0
- data/spec/support/test_environment.rb +30 -0
- metadata +306 -88
- data/generators/form/USAGE +0 -16
- data/generators/form/form_generator.rb +0 -111
- data/generators/formtastic/formtastic_generator.rb +0 -26
- data/init.rb +0 -5
- data/lib/formtastic/layout_helper.rb +0 -12
- data/lib/generators/formtastic/form/form_generator.rb +0 -84
- data/lib/generators/templates/formtastic.css +0 -145
- data/lib/generators/templates/formtastic_changes.css +0 -14
- data/lib/generators/templates/rails2/_form.html.erb +0 -5
- data/lib/generators/templates/rails2/_form.html.haml +0 -4
- data/rails/init.rb +0 -2
@@ -0,0 +1,87 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'time_zone input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
|
12
|
+
concat(semantic_form_for(@new_post) do |builder|
|
13
|
+
concat(builder.input(:time_zone))
|
14
|
+
end)
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_have_input_wrapper_with_class("time_zone")
|
18
|
+
it_should_have_input_wrapper_with_class(:input)
|
19
|
+
it_should_have_input_wrapper_with_id("post_time_zone_input")
|
20
|
+
it_should_apply_error_logic_for_input_type(:time_zone)
|
21
|
+
|
22
|
+
it 'should generate a label for the input' do
|
23
|
+
output_buffer.should have_tag('form li label')
|
24
|
+
output_buffer.should have_tag('form li label[@for="post_time_zone"]')
|
25
|
+
output_buffer.should have_tag('form li label', /Time zone/)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should generate a select" do
|
29
|
+
output_buffer.should have_tag("form li select")
|
30
|
+
output_buffer.should have_tag("form li select#post_time_zone")
|
31
|
+
output_buffer.should have_tag("form li select[@name=\"post[time_zone]\"]")
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should use input_html to style inputs' do
|
35
|
+
concat(semantic_form_for(@new_post) do |builder|
|
36
|
+
concat(builder.input(:time_zone, :input_html => { :class => 'myclass' }))
|
37
|
+
end)
|
38
|
+
output_buffer.should have_tag("form li select.myclass")
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "when namespace is provided" do
|
42
|
+
|
43
|
+
before do
|
44
|
+
@output_buffer = ''
|
45
|
+
mock_everything
|
46
|
+
|
47
|
+
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
|
48
|
+
concat(builder.input(:time_zone))
|
49
|
+
end)
|
50
|
+
end
|
51
|
+
|
52
|
+
it_should_have_input_wrapper_with_id("context2_post_time_zone_input")
|
53
|
+
it_should_have_select_with_id("context2_post_time_zone")
|
54
|
+
it_should_have_label_for("context2_post_time_zone")
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'when no object is given' do
|
59
|
+
before(:each) do
|
60
|
+
concat(semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
61
|
+
concat(builder.input(:time_zone, :as => :time_zone))
|
62
|
+
end)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should generate labels' do
|
66
|
+
output_buffer.should have_tag('form li label')
|
67
|
+
output_buffer.should have_tag('form li label[@for="project_time_zone"]')
|
68
|
+
output_buffer.should have_tag('form li label', /Time zone/)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should generate select inputs' do
|
72
|
+
output_buffer.should have_tag("form li select")
|
73
|
+
output_buffer.should have_tag("form li select#project_time_zone")
|
74
|
+
output_buffer.should have_tag("form li select[@name=\"project[time_zone]\"]")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "when required" do
|
79
|
+
it "should add the required attribute to the input's html options" do
|
80
|
+
concat(semantic_form_for(@new_post) do |builder|
|
81
|
+
concat(builder.input(:title, :as => :time_zone, :required => true))
|
82
|
+
end)
|
83
|
+
output_buffer.should have_tag("select[@required]")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'url input' do
|
5
|
+
|
6
|
+
include FormtasticSpecHelper
|
7
|
+
|
8
|
+
before do
|
9
|
+
@output_buffer = ''
|
10
|
+
mock_everything
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "when object is provided" do
|
14
|
+
before do
|
15
|
+
concat(semantic_form_for(@new_post) do |builder|
|
16
|
+
concat(builder.input(:url))
|
17
|
+
end)
|
18
|
+
end
|
19
|
+
|
20
|
+
it_should_have_input_wrapper_with_class(:url)
|
21
|
+
it_should_have_input_wrapper_with_class(:input)
|
22
|
+
it_should_have_input_wrapper_with_class(:stringish)
|
23
|
+
it_should_have_input_wrapper_with_id("post_url_input")
|
24
|
+
it_should_have_label_with_text(/Url/)
|
25
|
+
it_should_have_label_for("post_url")
|
26
|
+
it_should_have_input_with_id("post_url")
|
27
|
+
it_should_have_input_with_type(:url)
|
28
|
+
it_should_have_input_with_name("post[url]")
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "when namespace is provided" do
|
33
|
+
|
34
|
+
before do
|
35
|
+
concat(semantic_form_for(@new_post, :namespace => "context2") do |builder|
|
36
|
+
concat(builder.input(:url))
|
37
|
+
end)
|
38
|
+
end
|
39
|
+
|
40
|
+
it_should_have_input_wrapper_with_id("context2_post_url_input")
|
41
|
+
it_should_have_label_and_input_with_id("context2_post_url")
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "when required" do
|
46
|
+
it "should add the required attribute to the input's html options" do
|
47
|
+
concat(semantic_form_for(@new_post) do |builder|
|
48
|
+
concat(builder.input(:title, :as => :url, :required => true))
|
49
|
+
end)
|
50
|
+
output_buffer.should have_tag("input[@required]")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,361 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.setup
|
5
|
+
|
6
|
+
require 'active_support'
|
7
|
+
require 'action_pack'
|
8
|
+
require 'action_view'
|
9
|
+
require 'action_controller'
|
10
|
+
require 'action_dispatch'
|
11
|
+
|
12
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic/util'))
|
13
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic'))
|
14
|
+
|
15
|
+
# Requires supporting files with custom matchers and macros, etc,
|
16
|
+
# in ./support/ and its subdirectories in alphabetic order.
|
17
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each {|f| require f}
|
18
|
+
|
19
|
+
module FakeHelpersModule
|
20
|
+
end
|
21
|
+
|
22
|
+
module FormtasticSpecHelper
|
23
|
+
include ActionPack
|
24
|
+
include ActionView::Context if defined?(ActionView::Context)
|
25
|
+
include ActionController::RecordIdentifier
|
26
|
+
include ActionView::Helpers::FormHelper
|
27
|
+
include ActionView::Helpers::FormTagHelper
|
28
|
+
include ActionView::Helpers::FormOptionsHelper
|
29
|
+
include ActionView::Helpers::UrlHelper
|
30
|
+
include ActionView::Helpers::TagHelper
|
31
|
+
include ActionView::Helpers::TextHelper
|
32
|
+
include ActionView::Helpers::ActiveRecordHelper if defined?(ActionView::Helpers::ActiveRecordHelper)
|
33
|
+
include ActionView::Helpers::ActiveModelHelper if defined?(ActionView::Helpers::ActiveModelHelper)
|
34
|
+
include ActionView::Helpers::DateHelper
|
35
|
+
include ActionView::Helpers::CaptureHelper
|
36
|
+
include ActionView::Helpers::AssetTagHelper
|
37
|
+
include ActiveSupport
|
38
|
+
include ActionController::PolymorphicRoutes if defined?(ActionController::PolymorphicRoutes)
|
39
|
+
|
40
|
+
include Formtastic::Helpers::FormHelper
|
41
|
+
|
42
|
+
def default_input_type(column_type, column_name = :generic_column_name)
|
43
|
+
@new_post.stub!(column_name)
|
44
|
+
@new_post.stub!(:column_for_attribute).and_return(mock('column', :type => column_type)) unless column_type.nil?
|
45
|
+
|
46
|
+
semantic_form_for(@new_post) do |builder|
|
47
|
+
@default_type = builder.send(:default_input_type, column_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
return @default_type
|
51
|
+
end
|
52
|
+
|
53
|
+
def active_model_validator(kind, attributes, options = {})
|
54
|
+
validator = mock("ActiveModel::Validations::#{kind.to_s.titlecase}Validator", :attributes => attributes, :options => options)
|
55
|
+
validator.stub!(:kind).and_return(kind)
|
56
|
+
validator
|
57
|
+
end
|
58
|
+
|
59
|
+
def active_model_presence_validator(attributes, options = {})
|
60
|
+
active_model_validator(:presence, attributes, options)
|
61
|
+
end
|
62
|
+
|
63
|
+
def active_model_length_validator(attributes, options = {})
|
64
|
+
active_model_validator(:length, attributes, options)
|
65
|
+
end
|
66
|
+
|
67
|
+
def active_model_inclusion_validator(attributes, options = {})
|
68
|
+
active_model_validator(:inclusion, attributes, options)
|
69
|
+
end
|
70
|
+
|
71
|
+
def active_model_numericality_validator(attributes, options = {})
|
72
|
+
active_model_validator(:numericality, attributes, options)
|
73
|
+
end
|
74
|
+
|
75
|
+
class ::Post
|
76
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
77
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
78
|
+
|
79
|
+
def id
|
80
|
+
end
|
81
|
+
|
82
|
+
def persisted?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
module ::Namespaced
|
86
|
+
class Post
|
87
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
88
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
89
|
+
|
90
|
+
def id
|
91
|
+
end
|
92
|
+
|
93
|
+
def persisted?
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
class ::Author
|
98
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
99
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
100
|
+
|
101
|
+
def to_label
|
102
|
+
end
|
103
|
+
|
104
|
+
def persisted?
|
105
|
+
end
|
106
|
+
end
|
107
|
+
class ::Continent
|
108
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
109
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
110
|
+
end
|
111
|
+
class ::PostModel
|
112
|
+
extend ActiveModel::Naming if defined?(ActiveModel::Naming)
|
113
|
+
include ActiveModel::Conversion if defined?(ActiveModel::Conversion)
|
114
|
+
end
|
115
|
+
|
116
|
+
def _routes
|
117
|
+
url_helpers = mock('url_helpers')
|
118
|
+
url_helpers.stub!(:hash_for_posts_path).and_return({})
|
119
|
+
url_helpers.stub!(:hash_for_post_path).and_return({})
|
120
|
+
url_helpers.stub!(:hash_for_post_models_path).and_return({})
|
121
|
+
url_helpers.stub!(:hash_for_authors_path).and_return({})
|
122
|
+
|
123
|
+
mock('_routes',
|
124
|
+
:url_helpers => url_helpers,
|
125
|
+
:url_for => "/mock/path"
|
126
|
+
)
|
127
|
+
end
|
128
|
+
|
129
|
+
def controller
|
130
|
+
mock('controller', :controller_path= => '', :params => {})
|
131
|
+
end
|
132
|
+
|
133
|
+
def default_url_options
|
134
|
+
{}
|
135
|
+
end
|
136
|
+
|
137
|
+
def mock_everything
|
138
|
+
|
139
|
+
# Resource-oriented styles like form_for(@post) will expect a path method for the object,
|
140
|
+
# so we're defining some here.
|
141
|
+
def post_models_path; "/postmodels/1"; end
|
142
|
+
|
143
|
+
def post_path(o); "/posts/1"; end
|
144
|
+
def posts_path; "/posts"; end
|
145
|
+
def new_post_path; "/posts/new"; end
|
146
|
+
|
147
|
+
def author_path(o); "/authors/1"; end
|
148
|
+
def authors_path; "/authors"; end
|
149
|
+
def new_author_path; "/authors/new"; end
|
150
|
+
|
151
|
+
@fred = ::Author.new
|
152
|
+
@fred.stub!(:class).and_return(::Author)
|
153
|
+
@fred.stub!(:to_label).and_return('Fred Smith')
|
154
|
+
@fred.stub!(:login).and_return('fred_smith')
|
155
|
+
@fred.stub!(:age).and_return(27)
|
156
|
+
@fred.stub!(:id).and_return(37)
|
157
|
+
@fred.stub!(:new_record?).and_return(false)
|
158
|
+
@fred.stub!(:errors).and_return(mock('errors', :[] => nil))
|
159
|
+
@fred.stub!(:to_key).and_return(nil)
|
160
|
+
@fred.stub!(:persisted?).and_return(nil)
|
161
|
+
@fred.stub!(:name).and_return('Fred')
|
162
|
+
|
163
|
+
@bob = ::Author.new
|
164
|
+
@bob.stub!(:to_label).and_return('Bob Rock')
|
165
|
+
@bob.stub!(:login).and_return('bob')
|
166
|
+
@bob.stub!(:age).and_return(43)
|
167
|
+
@bob.stub!(:created_at)
|
168
|
+
@bob.stub!(:id).and_return(42)
|
169
|
+
@bob.stub!(:posts).and_return([])
|
170
|
+
@bob.stub!(:post_ids).and_return([])
|
171
|
+
@bob.stub!(:new_record?).and_return(false)
|
172
|
+
@bob.stub!(:errors).and_return(mock('errors', :[] => nil))
|
173
|
+
@bob.stub!(:to_key).and_return(nil)
|
174
|
+
@bob.stub!(:persisted?).and_return(nil)
|
175
|
+
@bob.stub!(:name).and_return('Bob')
|
176
|
+
|
177
|
+
@james = ::Author.new
|
178
|
+
@james.stub!(:to_label).and_return('James Shock')
|
179
|
+
@james.stub!(:login).and_return('james')
|
180
|
+
@james.stub!(:age).and_return(38)
|
181
|
+
@james.stub!(:id).and_return(75)
|
182
|
+
@james.stub!(:posts).and_return([])
|
183
|
+
@james.stub!(:post_ids).and_return([])
|
184
|
+
@james.stub!(:new_record?).and_return(false)
|
185
|
+
@james.stub!(:errors).and_return(mock('errors', :[] => nil))
|
186
|
+
@james.stub!(:to_key).and_return(nil)
|
187
|
+
@james.stub!(:persisted?).and_return(nil)
|
188
|
+
@james.stub!(:name).and_return('James')
|
189
|
+
|
190
|
+
|
191
|
+
::Author.stub!(:find).and_return([@fred, @bob])
|
192
|
+
::Author.stub!(:all).and_return([@fred, @bob])
|
193
|
+
::Author.stub!(:where).and_return([@fred, @bob])
|
194
|
+
::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
195
|
+
::Author.stub!(:human_name).and_return('::Author')
|
196
|
+
::Author.stub!(:reflect_on_association).and_return { |column_name| mock('reflection', :options => {}, :klass => Post, :macro => :has_many) if column_name == :posts }
|
197
|
+
::Author.stub!(:content_columns).and_return([mock('column', :name => 'login'), mock('column', :name => 'created_at')])
|
198
|
+
::Author.stub!(:to_key).and_return(nil)
|
199
|
+
::Author.stub!(:persisted?).and_return(nil)
|
200
|
+
|
201
|
+
# Sometimes we need a mock @post object and some Authors for belongs_to
|
202
|
+
@new_post = mock('post')
|
203
|
+
@new_post.stub!(:class).and_return(::Post)
|
204
|
+
@new_post.stub!(:id).and_return(nil)
|
205
|
+
@new_post.stub!(:new_record?).and_return(true)
|
206
|
+
@new_post.stub!(:errors).and_return(mock('errors', :[] => nil))
|
207
|
+
@new_post.stub!(:author).and_return(nil)
|
208
|
+
@new_post.stub!(:author_attributes=).and_return(nil)
|
209
|
+
@new_post.stub!(:authors).and_return([@fred])
|
210
|
+
@new_post.stub!(:authors_attributes=)
|
211
|
+
@new_post.stub!(:reviewer).and_return(nil)
|
212
|
+
@new_post.stub!(:main_post).and_return(nil)
|
213
|
+
@new_post.stub!(:sub_posts).and_return([]) #TODO should be a mock with methods for adding sub posts
|
214
|
+
@new_post.stub!(:to_key).and_return(nil)
|
215
|
+
@new_post.stub!(:to_model).and_return(@new_post)
|
216
|
+
@new_post.stub!(:persisted?).and_return(nil)
|
217
|
+
|
218
|
+
@freds_post = mock('post')
|
219
|
+
@freds_post.stub!(:to_ary)
|
220
|
+
@freds_post.stub!(:class).and_return(::Post)
|
221
|
+
@freds_post.stub!(:to_label).and_return('Fred Smith')
|
222
|
+
@freds_post.stub!(:id).and_return(19)
|
223
|
+
@freds_post.stub!(:title).and_return("Hello World")
|
224
|
+
@freds_post.stub!(:author).and_return(@fred)
|
225
|
+
@freds_post.stub!(:author_id).and_return(@fred.id)
|
226
|
+
@freds_post.stub!(:authors).and_return([@fred])
|
227
|
+
@freds_post.stub!(:author_ids).and_return([@fred.id])
|
228
|
+
@freds_post.stub!(:new_record?).and_return(false)
|
229
|
+
@freds_post.stub!(:errors).and_return(mock('errors', :[] => nil))
|
230
|
+
@freds_post.stub!(:to_key).and_return(nil)
|
231
|
+
@freds_post.stub!(:persisted?).and_return(nil)
|
232
|
+
@fred.stub!(:posts).and_return([@freds_post])
|
233
|
+
@fred.stub!(:post_ids).and_return([@freds_post.id])
|
234
|
+
|
235
|
+
::Post.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
236
|
+
::Post.stub!(:human_name).and_return('Post')
|
237
|
+
::Post.stub!(:reflect_on_all_validations).and_return([])
|
238
|
+
::Post.stub!(:reflect_on_validations_for).and_return([])
|
239
|
+
::Post.stub!(:reflections).and_return({})
|
240
|
+
::Post.stub!(:reflect_on_association).and_return do |column_name|
|
241
|
+
case column_name
|
242
|
+
when :author, :author_status
|
243
|
+
mock = mock('reflection', :options => {}, :klass => ::Author, :macro => :belongs_to)
|
244
|
+
mock.stub!(:[]).with(:class_name).and_return("Author")
|
245
|
+
mock
|
246
|
+
when :reviewer
|
247
|
+
mock = mock('reflection', :options => {:class_name => 'Author'}, :klass => ::Author, :macro => :belongs_to)
|
248
|
+
mock.stub!(:[]).with(:class_name).and_return("Author")
|
249
|
+
mock
|
250
|
+
when :authors
|
251
|
+
mock('reflection', :options => {}, :klass => ::Author, :macro => :has_and_belongs_to_many)
|
252
|
+
when :sub_posts
|
253
|
+
mock('reflection', :options => {}, :klass => ::Post, :macro => :has_many)
|
254
|
+
when :main_post
|
255
|
+
mock('reflection', :options => {}, :klass => ::Post, :macro => :belongs_to)
|
256
|
+
when :mongoid_reviewer
|
257
|
+
mock('reflection', :options => nil, :klass => ::Author, :macro => :referenced_in, :foreign_key => "reviewer_id") # custom id
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|
261
|
+
::Post.stub!(:find).and_return([@freds_post])
|
262
|
+
::Post.stub!(:all).and_return([@freds_post])
|
263
|
+
::Post.stub!(:where).and_return([@freds_post])
|
264
|
+
::Post.stub!(:content_columns).and_return([mock('column', :name => 'title'), mock('column', :name => 'body'), mock('column', :name => 'created_at')])
|
265
|
+
::Post.stub!(:to_key).and_return(nil)
|
266
|
+
::Post.stub!(:persisted?).and_return(nil)
|
267
|
+
::Post.stub!(:to_ary)
|
268
|
+
|
269
|
+
@mock_file = mock('file')
|
270
|
+
Formtastic::FormBuilder.file_methods.each do |method|
|
271
|
+
@mock_file.stub!(method).and_return(true)
|
272
|
+
end
|
273
|
+
|
274
|
+
@new_post.stub!(:title)
|
275
|
+
@new_post.stub!(:email)
|
276
|
+
@new_post.stub!(:url)
|
277
|
+
@new_post.stub!(:phone)
|
278
|
+
@new_post.stub!(:search)
|
279
|
+
@new_post.stub!(:to_ary)
|
280
|
+
@new_post.stub!(:body)
|
281
|
+
@new_post.stub!(:published)
|
282
|
+
@new_post.stub!(:publish_at)
|
283
|
+
@new_post.stub!(:created_at)
|
284
|
+
@new_post.stub!(:secret).and_return(1)
|
285
|
+
@new_post.stub!(:url)
|
286
|
+
@new_post.stub!(:email)
|
287
|
+
@new_post.stub!(:search)
|
288
|
+
@new_post.stub!(:phone)
|
289
|
+
@new_post.stub!(:time_zone)
|
290
|
+
@new_post.stub!(:category_name)
|
291
|
+
@new_post.stub!(:allow_comments).and_return(true)
|
292
|
+
@new_post.stub!(:answer_comments)
|
293
|
+
@new_post.stub!(:country)
|
294
|
+
@new_post.stub!(:country_subdivision)
|
295
|
+
@new_post.stub!(:country_code)
|
296
|
+
@new_post.stub!(:document).and_return(@mock_file)
|
297
|
+
@new_post.stub!(:column_for_attribute).with(:meta_description).and_return(mock('column', :type => :string, :limit => 255))
|
298
|
+
@new_post.stub!(:column_for_attribute).with(:title).and_return(mock('column', :type => :string, :limit => 50))
|
299
|
+
@new_post.stub!(:column_for_attribute).with(:body).and_return(mock('column', :type => :text))
|
300
|
+
@new_post.stub!(:column_for_attribute).with(:published).and_return(mock('column', :type => :boolean))
|
301
|
+
@new_post.stub!(:column_for_attribute).with(:publish_at).and_return(mock('column', :type => :date))
|
302
|
+
@new_post.stub!(:column_for_attribute).with(:time_zone).and_return(mock('column', :type => :string))
|
303
|
+
@new_post.stub!(:column_for_attribute).with(:allow_comments).and_return(mock('column', :type => :boolean))
|
304
|
+
@new_post.stub!(:column_for_attribute).with(:author).and_return(mock('column', :type => :integer))
|
305
|
+
@new_post.stub!(:column_for_attribute).with(:country).and_return(mock('column', :type => :string, :limit => 255))
|
306
|
+
@new_post.stub!(:column_for_attribute).with(:country_subdivision).and_return(mock('column', :type => :string, :limit => 255))
|
307
|
+
@new_post.stub!(:column_for_attribute).with(:country_code).and_return(mock('column', :type => :string, :limit => 255))
|
308
|
+
@new_post.stub!(:column_for_attribute).with(:email).and_return(mock('column', :type => :string, :limit => 255))
|
309
|
+
@new_post.stub!(:column_for_attribute).with(:url).and_return(mock('column', :type => :string, :limit => 255))
|
310
|
+
@new_post.stub!(:column_for_attribute).with(:phone).and_return(mock('column', :type => :string, :limit => 255))
|
311
|
+
@new_post.stub!(:column_for_attribute).with(:search).and_return(mock('column', :type => :string, :limit => 255))
|
312
|
+
@new_post.stub!(:column_for_attribute).with(:document).and_return(nil)
|
313
|
+
|
314
|
+
@new_post.stub!(:author).and_return(@bob)
|
315
|
+
@new_post.stub!(:author_id).and_return(@bob.id)
|
316
|
+
|
317
|
+
@new_post.stub!(:reviewer).and_return(@fred)
|
318
|
+
@new_post.stub!(:reviewer_id).and_return(@fred.id)
|
319
|
+
|
320
|
+
@new_post.should_receive(:publish_at=).any_number_of_times
|
321
|
+
@new_post.should_receive(:title=).any_number_of_times
|
322
|
+
@new_post.stub!(:main_post_id).and_return(nil)
|
323
|
+
|
324
|
+
end
|
325
|
+
|
326
|
+
def self.included(base)
|
327
|
+
base.class_eval do
|
328
|
+
|
329
|
+
attr_accessor :output_buffer
|
330
|
+
|
331
|
+
def protect_against_forgery?
|
332
|
+
false
|
333
|
+
end
|
334
|
+
|
335
|
+
def _helpers
|
336
|
+
FakeHelpersModule
|
337
|
+
end
|
338
|
+
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
def with_config(config_method_name, value, &block)
|
343
|
+
old_value = Formtastic::FormBuilder.send(config_method_name)
|
344
|
+
Formtastic::FormBuilder.send(:"#{config_method_name}=", value)
|
345
|
+
yield
|
346
|
+
Formtastic::FormBuilder.send(:"#{config_method_name}=", old_value)
|
347
|
+
end
|
348
|
+
|
349
|
+
end
|
350
|
+
|
351
|
+
::ActiveSupport::Deprecation.silenced = false
|
352
|
+
|
353
|
+
|
354
|
+
Rspec.configure do |config|
|
355
|
+
config.before(:all) do
|
356
|
+
DeferredGarbageCollection.start
|
357
|
+
end
|
358
|
+
config.after(:all) do
|
359
|
+
DeferredGarbageCollection.reconsider
|
360
|
+
end
|
361
|
+
end
|