foundation_rails_helper 0.2.1 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/.travis.yml +2 -1
- data/README.md +24 -19
- data/Rakefile +1 -1
- data/foundation_rails_helper.gemspec +3 -3
- data/lib/foundation_rails_helper/flash_helper.rb +13 -11
- data/lib/foundation_rails_helper/form_builder.rb +80 -44
- data/lib/foundation_rails_helper/version.rb +1 -1
- data/spec/foundation_rails_helper/flash_helper_spec.rb +37 -0
- data/spec/foundation_rails_helper/form_builder_spec.rb +86 -18
- data/spec/support/mock_rails.rb +5 -2
- metadata +35 -14
- data/spec/foundation_rails_helper/flash_spec.rb +0 -23
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,23 +1,22 @@
|
|
1
1
|
# FoundationRailsHelper [![Build Status](https://secure.travis-ci.org/sgruhier/foundation_rails_helper.png)](http://travis-ci.org/sgruhier/foundation_rails_helper)
|
2
2
|
|
3
|
-
Gem for
|
3
|
+
Gem for Rails 3 applications that use the excellent Zurb Foundation framework.
|
4
4
|
|
5
5
|
* [Zurb Foundation](https://github.com/zurb/foundation)
|
6
6
|
* [Zurb Foundation Rails](https://github.com/zurb/foundation-rails)
|
7
7
|
|
8
|
-
|
8
|
+
So far it includes:
|
9
9
|
|
10
|
-
* A
|
11
|
-
change your rails code.
|
12
|
-
Errors messages are propertly displayed
|
13
|
-
* A `display_flash_messages` helper method to use Zurb Foundation Alerts UI
|
10
|
+
* A custom FormBuilder that generates a form using the Foundation framework. It replaces the current `form_for` so you don't have to change your Rails code. Error messages are properly displayed.
|
14
11
|
|
15
|
-
|
12
|
+
* A `display_flash_messages` helper method that uses Zurb Foundation Alerts UI.
|
13
|
+
|
14
|
+
This gem has been used with Rails 3.1, 3.2 and ruby 1.9.2, 1.9.3. It should work for Rails 3.0.
|
16
15
|
|
17
16
|
## Screenshots
|
18
17
|
|
19
18
|
### Forms
|
20
|
-
A classic devise sign up
|
19
|
+
A classic devise sign up view will look like this:
|
21
20
|
|
22
21
|
```erb
|
23
22
|
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
|
@@ -28,6 +27,7 @@ A classic devise sign up views will look like this:
|
|
28
27
|
<%= f.submit %>
|
29
28
|
<% end %>
|
30
29
|
```
|
30
|
+
|
31
31
|
<table>
|
32
32
|
<tr>
|
33
33
|
<th>Form</th>
|
@@ -47,28 +47,33 @@ A classic devise sign up views will look like this:
|
|
47
47
|
|
48
48
|
Add this line to your application's Gemfile:
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
```ruby
|
51
|
+
gem 'zurb-foundation'
|
52
|
+
gem 'foundation_rails_helper'
|
53
|
+
```
|
52
54
|
|
53
55
|
And then execute:
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
+
```bash
|
58
|
+
$ bundle
|
59
|
+
```
|
57
60
|
|
58
61
|
## Usage
|
59
62
|
|
60
|
-
|
63
|
+
There is nothing additional to do for form helpers.
|
61
64
|
|
62
|
-
To get access to `display_flash_messages` in your views add
|
65
|
+
To get access to `display_flash_messages` in your views, add
|
63
66
|
|
67
|
+
```ruby
|
68
|
+
include FoundationRailsHelper::FlashHelper
|
64
69
|
```
|
65
|
-
|
66
|
-
|
70
|
+
|
71
|
+
to `app/helpers/application_helper.rb`
|
67
72
|
|
68
73
|
## TODO
|
69
74
|
|
70
75
|
* Handle more UI components
|
71
|
-
* Make
|
76
|
+
* Make something for ajax forms
|
72
77
|
|
73
78
|
## Contributing
|
74
79
|
|
@@ -76,8 +81,8 @@ To get access to `display_flash_messages` in your views add in your `app/helpers
|
|
76
81
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
77
82
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
78
83
|
4. Push to the branch (`git push origin my-new-feature`)
|
79
|
-
5. Create new Pull Request
|
80
|
-
|
84
|
+
5. Create a new Pull Request
|
81
85
|
|
82
86
|
## Copyright
|
87
|
+
|
83
88
|
Sébastien Gruhier (http://xilinus.com, http://v2.maptimize.com) - MIT LICENSE - 2012
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
require File.expand_path('../lib/foundation_rails_helper/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["
|
5
|
+
gem.authors = ["Sebastien Gruhier"]
|
6
6
|
gem.email = ["sebastien.gruhier@xilinus.com"]
|
7
7
|
gem.description = %q{Rails 3 for zurb foundation CSS framework. Form builder, flash message, ...}
|
8
8
|
gem.summary = %q{Rails 3 helpers for zurb foundation CSS framework}
|
@@ -14,8 +14,8 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.name = "foundation_rails_helper"
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = FoundationRailsHelper::VERSION
|
17
|
-
|
18
|
-
gem.add_dependency 'railties', '~> 3.0'
|
17
|
+
|
18
|
+
gem.add_dependency 'railties', '~> 3.0'
|
19
19
|
gem.add_dependency "actionpack", '~> 3.0'
|
20
20
|
gem.add_development_dependency "rspec-rails"
|
21
21
|
gem.add_development_dependency "capybara"
|
@@ -2,20 +2,22 @@ require 'action_view/helpers'
|
|
2
2
|
|
3
3
|
module FoundationRailsHelper
|
4
4
|
module FlashHelper
|
5
|
-
# <div class="alert-box [success
|
6
|
-
# This is
|
5
|
+
# <div class="alert-box [success alert secondary]">
|
6
|
+
# This is an alert box.
|
7
7
|
# <a href="" class="close">×</a>
|
8
8
|
# </div>
|
9
|
-
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
9
|
+
DEFAULT_KEY_MATCHING = {
|
10
|
+
:alert => :alert,
|
11
|
+
:notice => :success,
|
12
|
+
:info => :standard,
|
13
|
+
:secondary => :secondary,
|
14
14
|
}
|
15
|
-
def display_flash_messages
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
def display_flash_messages(key_matching = {})
|
16
|
+
key_matching = DEFAULT_KEY_MATCHING.merge(key_matching)
|
17
|
+
|
18
|
+
flash.inject "" do |message, (key, value)|
|
19
|
+
message += content_tag :div, :class => "alert-box #{key_matching[key] || :standard}" do
|
20
|
+
(value + link_to("×".html_safe, "#", :class => :close)).html_safe
|
19
21
|
end
|
20
22
|
end.html_safe
|
21
23
|
end
|
@@ -3,80 +3,116 @@ require 'action_view/helpers'
|
|
3
3
|
module FoundationRailsHelper
|
4
4
|
class FormBuilder < ActionView::Helpers::FormBuilder
|
5
5
|
include ActionView::Helpers::TagHelper
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
super(attribute, :class => class_name)
|
14
|
-
end
|
6
|
+
%w(file_field email_field text_field text_area telephone_field phone_field url_field number_field).each do |method_name|
|
7
|
+
define_method(method_name) do |*args|
|
8
|
+
attribute = args[0]
|
9
|
+
options = args[1] || {}
|
10
|
+
field(attribute, options) do |options|
|
11
|
+
super(attribute, options)
|
12
|
+
end
|
15
13
|
end
|
16
14
|
end
|
17
|
-
|
18
|
-
def check_box(attribute, options = {})
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
|
16
|
+
def check_box(attribute, options = {})
|
17
|
+
custom_label(attribute, options[:label], options[:label_options]) do
|
18
|
+
options.delete(:label)
|
19
|
+
options.delete(:label_options)
|
20
|
+
super(attribute, options)
|
21
|
+
end + error_and_hint(attribute, options)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def radio_button(attribute, tag_value, options = {})
|
25
25
|
options[:for] ||= "#{object.class.to_s.downcase}_#{attribute}_#{tag_value}"
|
26
26
|
l = label(attribute, options)
|
27
27
|
c = super(attribute, tag_value, options)
|
28
28
|
l.gsub(/(for=\"\w*\"\>)/, "\\1#{c} ").html_safe
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def password_field(attribute, options = {})
|
32
|
-
field attribute, options do |
|
33
|
-
super(attribute, :
|
32
|
+
field attribute, options do |options|
|
33
|
+
super(attribute, options.merge(:autocomplete => :off))
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def datetime_select(attribute, options = {})
|
38
|
-
field attribute, options do |
|
39
|
-
super(attribute, {}, :
|
38
|
+
field attribute, options do |options|
|
39
|
+
super(attribute, {}, options.merge(:autocomplete => :off))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def date_select(attribute, options = {}, html_options = {})
|
44
|
+
field attribute, html_options do |html_options|
|
45
|
+
super(attribute, options, html_options.merge(:autocomplete => :off))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def time_zone_select(attribute, options = {})
|
50
|
+
field attribute, options do |options|
|
51
|
+
super(attribute, {}, options.merge(:autocomplete => :off))
|
40
52
|
end
|
41
53
|
end
|
42
|
-
|
43
|
-
def
|
44
|
-
field attribute, options do |
|
45
|
-
|
54
|
+
|
55
|
+
def select(attribute, choices, options = {}, html_options = {})
|
56
|
+
field attribute, options do |options|
|
57
|
+
html_options[:autocomplete] ||= :off
|
58
|
+
super(attribute, choices, options, html_options)
|
46
59
|
end
|
47
60
|
end
|
48
|
-
|
61
|
+
|
49
62
|
def autocomplete(attribute, url, options = {})
|
50
|
-
field attribute, options do |
|
51
|
-
autocomplete_field(attribute, url, :
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
63
|
+
field attribute, options do |options|
|
64
|
+
autocomplete_field(attribute, url, options.merge(:update_elements => options[:update_elements],
|
65
|
+
:min_length => 0,
|
66
|
+
:value => object.send(attribute)))
|
67
|
+
end
|
56
68
|
end
|
57
69
|
|
58
70
|
def submit(value=nil, options={})
|
59
|
-
options[:class] ||= "
|
71
|
+
options[:class] ||= "small radius success button"
|
60
72
|
super(value, options)
|
61
73
|
end
|
62
|
-
|
74
|
+
|
63
75
|
private
|
64
|
-
def
|
65
|
-
|
66
|
-
|
76
|
+
def has_error?(attribute)
|
77
|
+
!object.errors[attribute].blank?
|
78
|
+
end
|
79
|
+
|
80
|
+
def error_for(attribute, options = {})
|
81
|
+
class_name = "error"
|
82
|
+
class_name += " #{options[:class]}" if options[:class]
|
83
|
+
content_tag(:small, object.errors[attribute].join(', '), :class => class_name) if has_error?(attribute)
|
84
|
+
end
|
85
|
+
|
86
|
+
def custom_label(attribute, text, options, &block)
|
87
|
+
if text == false
|
88
|
+
text = ""
|
89
|
+
elsif text.nil?
|
90
|
+
text = object.class.human_attribute_name(attribute)
|
91
|
+
end
|
92
|
+
text = block.call.html_safe + text if block_given?
|
93
|
+
options ||= {}
|
94
|
+
options[:class] ||= ""
|
95
|
+
options[:class] += " error" if has_error?(attribute)
|
96
|
+
label(attribute, text, options)
|
67
97
|
end
|
68
|
-
|
69
|
-
def error_and_hint(attribute)
|
98
|
+
|
99
|
+
def error_and_hint(attribute, options = {})
|
70
100
|
html = ""
|
71
101
|
html += content_tag(:span, options[:hint], :class => :hint) if options[:hint]
|
72
|
-
html += error_for(attribute) || ""
|
102
|
+
html += error_for(attribute, options) || ""
|
73
103
|
html.html_safe
|
74
104
|
end
|
75
|
-
|
105
|
+
|
76
106
|
def field(attribute, options, &block)
|
77
|
-
html =
|
78
|
-
html
|
79
|
-
|
107
|
+
html = ''.html_safe
|
108
|
+
html = custom_label(attribute, options[:label], options[:label_options]) if false != options[:label]
|
109
|
+
options[:class] ||= "medium"
|
110
|
+
options[:class] = "#{options[:class]} input-text"
|
111
|
+
options[:class] += " error" if has_error?(attribute)
|
112
|
+
options.delete(:label)
|
113
|
+
options.delete(:label_options)
|
114
|
+
html += yield(options)
|
115
|
+
html += error_and_hint(attribute, options)
|
80
116
|
end
|
81
117
|
end
|
82
118
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe FoundationRailsHelper::FlashHelper do
|
6
|
+
include ActionView::Context if defined?(ActionView::Context)
|
7
|
+
include ActionView::Helpers::UrlHelper
|
8
|
+
include ActionView::Helpers::TagHelper
|
9
|
+
include FoundationRailsHelper::FlashHelper
|
10
|
+
|
11
|
+
FoundationRailsHelper::FlashHelper::DEFAULT_KEY_MATCHING.each do |message_type, foundation_type|
|
12
|
+
it "displays flash message with #{foundation_type} class for #{message_type} message" do
|
13
|
+
self.stub!(:flash).and_return({message_type => "Flash message"})
|
14
|
+
node = Capybara.string display_flash_messages
|
15
|
+
node.should have_css("div.alert-box.#{foundation_type}", :text => "Flash message")
|
16
|
+
node.should have_css("div.alert-box a.close", :text => "×")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "displays flash message with overridden key matching" do
|
21
|
+
self.stub!(:flash).and_return({:notice => "Flash message"})
|
22
|
+
node = Capybara.string display_flash_messages({:notice => :alert})
|
23
|
+
node.should have_css("div.alert-box.alert")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "displays flash message with custom key matching" do
|
27
|
+
self.stub!(:flash).and_return({:custom_type => "Flash message"})
|
28
|
+
node = Capybara.string display_flash_messages({:custom_type => :custom_class})
|
29
|
+
node.should have_css("div.alert-box.custom_class")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "displays flash message with standard class if key doesn't match" do
|
33
|
+
self.stub!(:flash).and_return({:custom_type => "Flash message"})
|
34
|
+
node = Capybara.string display_flash_messages
|
35
|
+
node.should have_css("div.alert-box.standard")
|
36
|
+
end
|
37
|
+
end
|
@@ -10,7 +10,7 @@ describe "FoundationRailsHelper::FormHelper" do
|
|
10
10
|
it 'should have FoundationRailsHelper::FormHelper as default buidler' do
|
11
11
|
form_for(@author) do |builder|
|
12
12
|
builder.class.should == FoundationRailsHelper::FormBuilder
|
13
|
-
end
|
13
|
+
end
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "input generators" do
|
@@ -20,24 +20,60 @@ describe "FoundationRailsHelper::FormHelper" do
|
|
20
20
|
node.should have_css('label[for="author_login"]', :text => "Login")
|
21
21
|
node.should have_css('input.medium.input-text[type="text"][name="author[login]"]')
|
22
22
|
node.find_field('author_login').value.should == @author.login
|
23
|
-
end
|
23
|
+
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
|
+
it "should generate text_field input without label" do
|
27
|
+
form_for(@author) do |builder|
|
28
|
+
node = Capybara.string builder.text_field(:login, :label => false)
|
29
|
+
node.should_not have_css('label[for="author_login"]', :text => "Login")
|
30
|
+
node.should have_css('input.medium.input-text[type="text"][name="author[login]"]')
|
31
|
+
node.find_field('author_login').value.should == @author.login
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
26
35
|
it "should generate password_field input" do
|
27
36
|
form_for(@author) do |builder|
|
28
37
|
node = Capybara.string builder.password_field(:password)
|
29
38
|
node.should have_css('label[for="author_password"]', :text => "Password")
|
30
39
|
node.should have_css('input.medium.input-text[type="password"][name="author[password]"]')
|
31
40
|
node.find_field('author_password').value.should be_nil
|
32
|
-
end
|
41
|
+
end
|
33
42
|
end
|
34
|
-
|
43
|
+
|
35
44
|
it "should generate email_field input" do
|
36
45
|
form_for(@author) do |builder|
|
37
46
|
node = Capybara.string builder.email_field(:email)
|
38
47
|
node.should have_css('label[for="author_email"]', :text => "Email")
|
39
48
|
node.should have_css('input.medium.input-text[type="email"][name="author[email]"]')
|
40
49
|
node.find_field('author_email').value.should == @author.email
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should generate url_field input" do
|
54
|
+
form_for(@author) do |builder|
|
55
|
+
node = Capybara.string builder.url_field(:url)
|
56
|
+
node.should have_css('label[for="author_url"]', :text => "Url")
|
57
|
+
node.should have_css('input.medium.input-text[type="url"][name="author[url]"]')
|
58
|
+
node.find_field('author_url').value.should == @author.url
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should generate phone_field input" do
|
63
|
+
form_for(@author) do |builder|
|
64
|
+
node = Capybara.string builder.phone_field(:phone)
|
65
|
+
node.should have_css('label[for="author_phone"]', :text => "Phone")
|
66
|
+
node.should have_css('input.medium.input-text[type="tel"][name="author[phone]"]')
|
67
|
+
node.find_field('author_phone').value.should == @author.phone
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should generate number_field input" do
|
72
|
+
form_for(@author) do |builder|
|
73
|
+
node = Capybara.string builder.number_field(:some_number)
|
74
|
+
node.should have_css('label[for="author_some_number"]', :text => "Some number")
|
75
|
+
node.should have_css('input.medium.input-text[type="number"][name="author[some_number]"]')
|
76
|
+
node.find_field('author_some_number').value.should == @author.some_number
|
41
77
|
end
|
42
78
|
end
|
43
79
|
|
@@ -46,47 +82,79 @@ describe "FoundationRailsHelper::FormHelper" do
|
|
46
82
|
node = Capybara.string builder.text_area(:description)
|
47
83
|
node.should have_css('label[for="author_description"]', :text => "Description")
|
48
84
|
node.should have_css('textarea.medium.input-text[name="author[description]"]')
|
49
|
-
node.find_field('author_description').value.should == @author.description
|
50
|
-
end
|
85
|
+
node.find_field('author_description').value.strip.should == @author.description
|
86
|
+
end
|
51
87
|
end
|
52
|
-
|
88
|
+
|
53
89
|
it "should generate file_field input" do
|
54
90
|
form_for(@author) do |builder|
|
55
91
|
node = Capybara.string builder.file_field(:avatar)
|
56
92
|
node.should have_css('label[for="author_avatar"]', :text => "Avatar")
|
57
93
|
node.should have_css('input.medium.input-text[type="file"][name="author[avatar]"]')
|
58
94
|
node.find_field('author_avatar').value.should be_nil
|
59
|
-
end
|
95
|
+
end
|
60
96
|
end
|
61
|
-
|
97
|
+
|
98
|
+
it "should generate select input" do
|
99
|
+
form_for(@author) do |builder|
|
100
|
+
node = Capybara.string builder.select(:description, [["Choice #1", :a], ["Choice #2", :b]])
|
101
|
+
node.should have_css('label[for="author_description"]', :text => "Description")
|
102
|
+
node.should have_css('select[name="author[description]"]')
|
103
|
+
node.should have_css('select[name="author[description]"] option[value="a"]', :text => "Choice #1")
|
104
|
+
node.should have_css('select[name="author[description]"] option[value="b"]', :text => "Choice #2")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
62
108
|
it "should generate check_box input" do
|
63
109
|
form_for(@author) do |builder|
|
64
110
|
node = Capybara.string builder.check_box(:active)
|
65
111
|
node.should have_css('label[for="author_active"] input[type="hidden"][name="author[active]"][value="0"]')
|
66
112
|
node.should have_css('label[for="author_active"] input[type="checkbox"][name="author[active]"]')
|
67
|
-
|
113
|
+
node.should have_css('label[for="author_active"]', :text => "Active")
|
114
|
+
end
|
68
115
|
end
|
69
|
-
|
116
|
+
it "should generate check_box input without a label" do
|
117
|
+
form_for(@author) do |builder|
|
118
|
+
node = Capybara.string builder.check_box(:active, :label => false)
|
119
|
+
node.should have_css('label[for="author_active"] input[type="hidden"][name="author[active]"][value="0"]')
|
120
|
+
node.should have_css('label[for="author_active"] input[type="checkbox"][name="author[active]"]')
|
121
|
+
node.should have_css('label[for="author_active"]', :text => "")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
70
125
|
it "should generate radio_button input" do
|
71
126
|
form_for(@author) do |builder|
|
72
|
-
node = Capybara.string builder.radio_button(:active, "ok")
|
127
|
+
node = Capybara.string builder.label(:active) + builder.radio_button(:active, "ok")
|
73
128
|
node.should have_css('label[for="author_active_ok"] input[type="radio"][name="author[active]"]')
|
74
|
-
end
|
129
|
+
end
|
75
130
|
end
|
76
|
-
|
131
|
+
|
77
132
|
it "should generate date_select input" do
|
78
133
|
form_for(@author) do |builder|
|
79
|
-
node = Capybara.string builder.date_select(:birthdate)
|
134
|
+
node = Capybara.string builder.label(:birthdate) + builder.date_select(:birthdate)
|
80
135
|
node.should have_css('label[for="author_birthdate"]', :text => "Birthdate")
|
81
136
|
%w(1 2 3).each {|i| node.should have_css("select.medium.input-text[name='author[birthdate(#{i}i)]']") }
|
82
137
|
node.should have_css('select#author_birthdate_1i option[selected="selected"][value="1969"]')
|
83
138
|
node.should have_css('select#author_birthdate_2i option[selected="selected"][value="6"]')
|
84
139
|
node.should have_css('select#author_birthdate_3i option[selected="selected"][value="18"]')
|
85
140
|
%w(4 5).each {|i| node.should_not have_css("select.medium.input-text[name='author[birthdate(#{i}i)]']") }
|
86
|
-
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should generate date_select input with :discard_year => true" do
|
145
|
+
form_for(@author) do |builder|
|
146
|
+
node = Capybara.string builder.label(:birthdate) + builder.date_select(:birthdate, :discard_year => true)
|
147
|
+
node.should have_css('label[for="author_birthdate"]', :text => "Birthdate")
|
148
|
+
%w(2 3).each {|i| node.should have_css("select.medium.input-text[name='author[birthdate(#{i}i)]']") }
|
149
|
+
node.should_not have_css('select#author_birthdate_1i option[selected="selected"][value="1969"]')
|
150
|
+
node.should have_css('select#author_birthdate_2i option[selected="selected"][value="6"]')
|
151
|
+
node.should have_css('select#author_birthdate_3i option[selected="selected"][value="18"]')
|
152
|
+
%w(1 4 5).each {|i| node.should_not have_css("select.medium.input-text[name='author[birthdate(#{i}i)]']") }
|
153
|
+
end
|
87
154
|
end
|
155
|
+
|
88
156
|
end
|
89
|
-
|
157
|
+
|
90
158
|
describe "errors generator" do
|
91
159
|
it "should not display errors" do
|
92
160
|
form_for(@author) do |builder|
|
data/spec/support/mock_rails.rb
CHANGED
@@ -56,7 +56,7 @@ module FoundationRailsSpecHelper
|
|
56
56
|
def persisted?
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def mock_everything
|
61
61
|
# Resource-oriented styles like form_for(@post) will expect a path method for the object,
|
62
62
|
# so we're defining some here.
|
@@ -69,6 +69,9 @@ module FoundationRailsSpecHelper
|
|
69
69
|
@author.stub!(:to_label).and_return('Fred Smith')
|
70
70
|
@author.stub!(:login).and_return('fred_smith')
|
71
71
|
@author.stub!(:email).and_return('fred@foo.com')
|
72
|
+
@author.stub!(:url).and_return('http://example.com')
|
73
|
+
@author.stub!(:some_number).and_return('42')
|
74
|
+
@author.stub!(:phone).and_return('317 456 2564')
|
72
75
|
@author.stub!(:password).and_return('secret')
|
73
76
|
@author.stub!(:active).and_return(true)
|
74
77
|
@author.stub!(:description).and_return('bla bla bla')
|
@@ -84,7 +87,7 @@ module FoundationRailsSpecHelper
|
|
84
87
|
::Author.stub!(:find).and_return([@author])
|
85
88
|
::Author.stub!(:all).and_return([@author])
|
86
89
|
::Author.stub!(:where).and_return([@author])
|
87
|
-
::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
|
90
|
+
::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.to_s.humanize }
|
88
91
|
::Author.stub!(:human_name).and_return('::Author')
|
89
92
|
::Author.stub!(:content_columns).and_return([mock('column', :name => 'login'), mock('column', :name => 'created_at')])
|
90
93
|
::Author.stub!(:to_key).and_return(nil)
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foundation_rails_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.3'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
-
|
8
|
+
- Sebastien Gruhier
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: actionpack
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '3.0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rspec-rails
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: capybara
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,7 +69,12 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
description: Rails 3 for zurb foundation CSS framework. Form builder, flash message,
|
59
79
|
...
|
60
80
|
email:
|
@@ -64,6 +84,7 @@ extensions: []
|
|
64
84
|
extra_rdoc_files: []
|
65
85
|
files:
|
66
86
|
- .gitignore
|
87
|
+
- .rspec
|
67
88
|
- .travis.yml
|
68
89
|
- CHANGELOG.md
|
69
90
|
- Gemfile
|
@@ -77,7 +98,7 @@ files:
|
|
77
98
|
- lib/foundation_rails_helper/form_builder.rb
|
78
99
|
- lib/foundation_rails_helper/version.rb
|
79
100
|
- lib/railtie.rb
|
80
|
-
- spec/foundation_rails_helper/
|
101
|
+
- spec/foundation_rails_helper/flash_helper_spec.rb
|
81
102
|
- spec/foundation_rails_helper/form_builder_spec.rb
|
82
103
|
- spec/spec_helper.rb
|
83
104
|
- spec/support/mock_rails.rb
|
@@ -101,12 +122,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
122
|
version: '0'
|
102
123
|
requirements: []
|
103
124
|
rubyforge_project:
|
104
|
-
rubygems_version: 1.8.
|
125
|
+
rubygems_version: 1.8.23
|
105
126
|
signing_key:
|
106
127
|
specification_version: 3
|
107
128
|
summary: Rails 3 helpers for zurb foundation CSS framework
|
108
129
|
test_files:
|
109
|
-
- spec/foundation_rails_helper/
|
130
|
+
- spec/foundation_rails_helper/flash_helper_spec.rb
|
110
131
|
- spec/foundation_rails_helper/form_builder_spec.rb
|
111
132
|
- spec/spec_helper.rb
|
112
133
|
- spec/support/mock_rails.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "FoundationRailsHelper::FlashHelper" do
|
4
|
-
include ActionView::Context if defined?(ActionView::Context)
|
5
|
-
include ActionView::Helpers::UrlHelper
|
6
|
-
include ActionView::Helpers::TagHelper
|
7
|
-
include FoundationRailsHelper::FlashHelper
|
8
|
-
|
9
|
-
%w(error warning success).each do |message_type|
|
10
|
-
it "should display a flash for #{message_type} message" do
|
11
|
-
self.stub!(:flash).and_return({message_type => "Error message"})
|
12
|
-
node = Capybara.string display_flash_messages
|
13
|
-
node.should have_css("div.alert-box.#{message_type}", :text => "Error message")
|
14
|
-
node.should have_css("div.alert-box a.close", :text => "x")
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
it "should use flash key matching" do
|
19
|
-
self.stub!(:flash).and_return({:notice => "Error message"})
|
20
|
-
node = Capybara.string display_flash_messages
|
21
|
-
node.should have_css("div.alert-box.success")
|
22
|
-
end
|
23
|
-
end
|