need_label 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,25 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ #gem 'activerecord', rails_version
7
+ #gem 'actionpack', rails_version
8
+ gem 'rails',">= 3.0.7"
9
+
10
+ # Add dependencies to develop your gem here.
11
+ # Include everything needed to run rake, tests, features, etc.
12
+ group :development do
13
+ gem "rspec", "~> 2.7.0"
14
+ gem "bundler","~> 1.0.0"
15
+ gem "jeweler", "~> 1.6.4"
16
+ gem "rcov", ">= 0"
17
+ gem 'sqlite3',"~> 1.3.0"
18
+ gem 'rspec-rails', "~> 2.7.0"
19
+ gem 'capybara', "~> 1.1.0"
20
+ gem 'nokogiri', "~> 1.5.0"
21
+ end
22
+
23
+ group :test do
24
+ gem 'rr', "~> 1.0.0"
25
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,138 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.1.1)
5
+ actionpack (= 3.1.1)
6
+ mail (~> 2.3.0)
7
+ actionpack (3.1.1)
8
+ activemodel (= 3.1.1)
9
+ activesupport (= 3.1.1)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ i18n (~> 0.6)
13
+ rack (~> 1.3.2)
14
+ rack-cache (~> 1.1)
15
+ rack-mount (~> 0.8.2)
16
+ rack-test (~> 0.6.1)
17
+ sprockets (~> 2.0.2)
18
+ activemodel (3.1.1)
19
+ activesupport (= 3.1.1)
20
+ builder (~> 3.0.0)
21
+ i18n (~> 0.6)
22
+ activerecord (3.1.1)
23
+ activemodel (= 3.1.1)
24
+ activesupport (= 3.1.1)
25
+ arel (~> 2.2.1)
26
+ tzinfo (~> 0.3.29)
27
+ activeresource (3.1.1)
28
+ activemodel (= 3.1.1)
29
+ activesupport (= 3.1.1)
30
+ activesupport (3.1.1)
31
+ multi_json (~> 1.0)
32
+ arel (2.2.1)
33
+ builder (3.0.0)
34
+ capybara (1.1.1)
35
+ mime-types (>= 1.16)
36
+ nokogiri (>= 1.3.3)
37
+ rack (>= 1.0.0)
38
+ rack-test (>= 0.5.4)
39
+ selenium-webdriver (~> 2.0)
40
+ xpath (~> 0.1.4)
41
+ childprocess (0.2.2)
42
+ ffi (~> 1.0.6)
43
+ diff-lcs (1.1.3)
44
+ erubis (2.7.0)
45
+ ffi (1.0.9)
46
+ git (1.2.5)
47
+ hike (1.2.1)
48
+ i18n (0.6.0)
49
+ jeweler (1.6.4)
50
+ bundler (~> 1.0)
51
+ git (>= 1.2.5)
52
+ rake
53
+ json (1.6.1)
54
+ json_pure (1.6.1)
55
+ mail (2.3.0)
56
+ i18n (>= 0.4.0)
57
+ mime-types (~> 1.16)
58
+ treetop (~> 1.4.8)
59
+ mime-types (1.17.2)
60
+ multi_json (1.0.3)
61
+ nokogiri (1.5.0)
62
+ polyglot (0.3.2)
63
+ rack (1.3.5)
64
+ rack-cache (1.1)
65
+ rack (>= 0.4)
66
+ rack-mount (0.8.3)
67
+ rack (>= 1.0.0)
68
+ rack-ssl (1.3.2)
69
+ rack
70
+ rack-test (0.6.1)
71
+ rack (>= 1.0)
72
+ rails (3.1.1)
73
+ actionmailer (= 3.1.1)
74
+ actionpack (= 3.1.1)
75
+ activerecord (= 3.1.1)
76
+ activeresource (= 3.1.1)
77
+ activesupport (= 3.1.1)
78
+ bundler (~> 1.0)
79
+ railties (= 3.1.1)
80
+ railties (3.1.1)
81
+ actionpack (= 3.1.1)
82
+ activesupport (= 3.1.1)
83
+ rack-ssl (~> 1.3.2)
84
+ rake (>= 0.8.7)
85
+ rdoc (~> 3.4)
86
+ thor (~> 0.14.6)
87
+ rake (0.9.2.2)
88
+ rcov (0.9.11)
89
+ rdoc (3.11)
90
+ json (~> 1.4)
91
+ rr (1.0.4)
92
+ rspec (2.7.0)
93
+ rspec-core (~> 2.7.0)
94
+ rspec-expectations (~> 2.7.0)
95
+ rspec-mocks (~> 2.7.0)
96
+ rspec-core (2.7.1)
97
+ rspec-expectations (2.7.0)
98
+ diff-lcs (~> 1.1.2)
99
+ rspec-mocks (2.7.0)
100
+ rspec-rails (2.7.0)
101
+ actionpack (~> 3.0)
102
+ activesupport (~> 3.0)
103
+ railties (~> 3.0)
104
+ rspec (~> 2.7.0)
105
+ rubyzip (0.9.4)
106
+ selenium-webdriver (2.10.0)
107
+ childprocess (>= 0.2.1)
108
+ ffi (= 1.0.9)
109
+ json_pure
110
+ rubyzip
111
+ sprockets (2.0.3)
112
+ hike (~> 1.2)
113
+ rack (~> 1.0)
114
+ tilt (~> 1.1, != 1.3.0)
115
+ sqlite3 (1.3.4)
116
+ thor (0.14.6)
117
+ tilt (1.3.3)
118
+ treetop (1.4.10)
119
+ polyglot
120
+ polyglot (>= 0.3.1)
121
+ tzinfo (0.3.30)
122
+ xpath (0.1.4)
123
+ nokogiri (~> 1.3)
124
+
125
+ PLATFORMS
126
+ ruby
127
+
128
+ DEPENDENCIES
129
+ bundler (~> 1.0.0)
130
+ capybara (~> 1.1.0)
131
+ jeweler (~> 1.6.4)
132
+ nokogiri (~> 1.5.0)
133
+ rails (>= 3.0.7)
134
+ rcov
135
+ rr (~> 1.0.0)
136
+ rspec (~> 2.7.0)
137
+ rspec-rails (~> 2.7.0)
138
+ sqlite3 (~> 1.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Yamamoto Kazuhisa
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,10 @@
1
+ = need_label
2
+
3
+ Need_label outputs a class attribute to the indispensable input item of rails.
4
+ An indispensable input can be expressed by combining with css.
5
+
6
+ == Copyright
7
+
8
+ Copyright (c) 2011 Yamamoto Kazuhisa. See LICENSE.txt for
9
+ further details.
10
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "need_label"
18
+ gem.homepage = "http://github.com/kazuhisa/need_label"
19
+ gem.license = "MIT"
20
+ gem.summary = "output need-label"
21
+ gem.description = "A class is outputted about an indispensable input item."
22
+ gem.email = "ak.hisashi@gmail.com"
23
+ gem.authors = ["Yamamoto Kazuhisa"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "need_label #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module FormHelper
6
+ def need_label(object_name, object, method, content_or_options = nil, options = nil, &block)
7
+ need = true
8
+ if content_or_options.class == Hash && content_or_options[:need_label] == false
9
+ need = false
10
+ content_or_options.delete(:need_label)
11
+ content_or_options = nil if content_or_options == {}
12
+ end
13
+ need = false if options.class == Hash && options[:need_label] == false
14
+ if need && object.present? && object.class.respond_to?(:validators)
15
+ need_attributes = object.class.validators.
16
+ select{|e| e.is_a? ActiveModel::Validations::PresenceValidator}.map{|e| e.attributes[0]}
17
+ if need_attributes.index(method.to_sym)
18
+ if content_or_options.present? && content_or_options.class == Hash && content_or_options[:class].present?
19
+ content_or_options[:class] = content_or_options[:class] + " need-label"
20
+ else
21
+ options[:class] = "need-label"
22
+ end
23
+ end
24
+ end
25
+ label(object_name, method, content_or_options, options, &block)
26
+ end
27
+ end
28
+
29
+ class FormBuilder
30
+ def label(method, text = nil, options = {}, &block)
31
+ if @object_name.class == Symbol
32
+ @object = @template.instance_variable_get("@#{@object_name}")
33
+ end
34
+ @template.need_label(@object_name, @object, method, text, objectify_options(options), &block)
35
+ end
36
+ end
37
+ end
38
+ end
data/lib/need_label.rb ADDED
@@ -0,0 +1,3 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'need_label/helpers'
@@ -0,0 +1,77 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{need_label}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Yamamoto Kazuhisa}]
12
+ s.date = %q{2011-10-31}
13
+ s.description = %q{A class is outputted about an indispensable input item.}
14
+ s.email = %q{ak.hisashi@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/need_label.rb",
29
+ "lib/need_label/helpers.rb",
30
+ "need_label.gemspec",
31
+ "spec/fake_app.rb",
32
+ "spec/requests/need_label_spec.rb",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/kazuhisa/need_label}
36
+ s.licenses = [%q{MIT}]
37
+ s.require_paths = [%q{lib}]
38
+ s.rubygems_version = %q{1.8.6}
39
+ s.summary = %q{output need-label}
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<rails>, [">= 3.0.7"])
46
+ s.add_development_dependency(%q<rspec>, ["~> 2.7.0"])
47
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
49
+ s.add_development_dependency(%q<rcov>, [">= 0"])
50
+ s.add_development_dependency(%q<sqlite3>, ["~> 1.3.0"])
51
+ s.add_development_dependency(%q<rspec-rails>, ["~> 2.7.0"])
52
+ s.add_development_dependency(%q<capybara>, ["~> 1.1.0"])
53
+ s.add_development_dependency(%q<nokogiri>, ["~> 1.5.0"])
54
+ else
55
+ s.add_dependency(%q<rails>, [">= 3.0.7"])
56
+ s.add_dependency(%q<rspec>, ["~> 2.7.0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
59
+ s.add_dependency(%q<rcov>, [">= 0"])
60
+ s.add_dependency(%q<sqlite3>, ["~> 1.3.0"])
61
+ s.add_dependency(%q<rspec-rails>, ["~> 2.7.0"])
62
+ s.add_dependency(%q<capybara>, ["~> 1.1.0"])
63
+ s.add_dependency(%q<nokogiri>, ["~> 1.5.0"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<rails>, [">= 3.0.7"])
67
+ s.add_dependency(%q<rspec>, ["~> 2.7.0"])
68
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
69
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
70
+ s.add_dependency(%q<rcov>, [">= 0"])
71
+ s.add_dependency(%q<sqlite3>, ["~> 1.3.0"])
72
+ s.add_dependency(%q<rspec-rails>, ["~> 2.7.0"])
73
+ s.add_dependency(%q<capybara>, ["~> 1.1.0"])
74
+ s.add_dependency(%q<nokogiri>, ["~> 1.5.0"])
75
+ end
76
+ end
77
+
data/spec/fake_app.rb ADDED
@@ -0,0 +1,39 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'active_record'
3
+ require 'action_controller/railtie'
4
+ require 'action_view/helpers'
5
+ require 'need_label'
6
+
7
+ # database
8
+ ActiveRecord::Base.configurations = {'test' => {:adapter => 'sqlite3', :database => ':memory:'}}
9
+ ActiveRecord::Base.establish_connection('test')
10
+
11
+ # config
12
+ app = Class.new(Rails::Application)
13
+ app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
14
+ app.config.session_store :cookie_store, :key => "_myapp_session"
15
+ app.config.active_support.deprecation = :log
16
+ app.initialize!
17
+
18
+ # routes
19
+ app.routes.draw do
20
+ resources :users
21
+ end
22
+
23
+ # models
24
+ class User < ActiveRecord::Base
25
+ validates :name, :presence => true
26
+ end
27
+
28
+ # controllers
29
+ class ApplicationController < ActionController::Base; end
30
+
31
+ # helpers
32
+ Object.const_set(:ApplicationHelper, Module.new)
33
+
34
+ #migrations
35
+ class CreateAllTables < ActiveRecord::Migration
36
+ def self.up
37
+ create_table(:users) {|t| t.string :name; t.integer :age}
38
+ end
39
+ end
@@ -0,0 +1,243 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "output need-label class" do
4
+ describe "instance variable type without options" do
5
+ before do
6
+ class UsersController < ApplicationController
7
+ def new
8
+ @user = User.new
9
+ render :inline => <<-ERB
10
+ <%= form_for @user do |f| %>
11
+ <%= f.label :name %>
12
+ <%= f.text_field :name %>
13
+ <%= f.label :age %>
14
+ <%= f.text_field :age %>
15
+ <%= f.submit "save" %>
16
+ <% end %>
17
+ ERB
18
+ end
19
+ end
20
+ visit "/users/new"
21
+ end
22
+ it "It checks that need-label is outputted." do
23
+ doc = Nokogiri::HTML(page.html)
24
+ label = doc.xpath("//label[@for='user_name']")
25
+ label[0]["class"].should == "need-label"
26
+ end
27
+ it "It checks that need-label is not outputted." do
28
+ doc = Nokogiri::HTML(page.html)
29
+ label = doc.xpath("//label[@for='user_age']")
30
+ label[0]["class"].should be_nil
31
+ end
32
+ end
33
+
34
+ describe "symbol type without options" do
35
+ before do
36
+ class UsersController < ApplicationController
37
+ def new
38
+ @user = User.new
39
+ render :inline => <<-ERB
40
+ <%= form_for :user do |f| %>
41
+ <%= f.label :name %>
42
+ <%= f.text_field :name %>
43
+ <%= f.label :age %>
44
+ <%= f.text_field :age %>
45
+ <%= f.submit "save" %>
46
+ <% end %>
47
+ ERB
48
+ end
49
+ end
50
+ visit "/users/new"
51
+ end
52
+ it "It checks that need-label is outputted." do
53
+ doc = Nokogiri::HTML(page.html)
54
+ label = doc.xpath("//label[@for='user_name']")
55
+ label[0]["class"].should == "need-label"
56
+ end
57
+ it "It checks that need-label is not outputted." do
58
+ doc = Nokogiri::HTML(page.html)
59
+ label = doc.xpath("//label[@for='user_age']")
60
+ label[0]["class"].should be_nil
61
+ end
62
+ end
63
+
64
+ describe "instance variable type with hidden option" do
65
+ before do
66
+ class UsersController < ApplicationController
67
+ def new
68
+ @user = User.new
69
+ render :inline => <<-ERB
70
+ <%= form_for @user do |f| %>
71
+ <%= f.label :name, :need_label => false %>
72
+ <%= f.text_field :name %>
73
+ <%= f.label :age %>
74
+ <%= f.text_field :age %>
75
+ <%= f.submit "save" %>
76
+ <% end %>
77
+ ERB
78
+ end
79
+ end
80
+ visit "/users/new"
81
+ end
82
+ it "It checks that need-label is outputted." do
83
+ doc = Nokogiri::HTML(page.html)
84
+ label = doc.xpath("//label[@for='user_name']")
85
+ label[0]["class"].should be_nil
86
+ end
87
+ it "It checks that need-label is not outputted." do
88
+ doc = Nokogiri::HTML(page.html)
89
+ label = doc.xpath("//label[@for='user_age']")
90
+ label[0]["class"].should be_nil
91
+ end
92
+ end
93
+
94
+ describe "symbol type with hidden option" do
95
+ before do
96
+ class UsersController < ApplicationController
97
+ def new
98
+ @user = User.new
99
+ render :inline => <<-ERB
100
+ <%= form_for :user do |f| %>
101
+ <%= f.label :name, :need_label => false %>
102
+ <%= f.text_field :name %>
103
+ <%= f.label :age %>
104
+ <%= f.text_field :age %>
105
+ <%= f.submit "save" %>
106
+ <% end %>
107
+ ERB
108
+ end
109
+ end
110
+ visit "/users/new"
111
+ end
112
+ it "It checks that need-label is outputted." do
113
+ doc = Nokogiri::HTML(page.html)
114
+ label = doc.xpath("//label[@for='user_name']")
115
+ label[0]["class"].should be_nil
116
+ end
117
+ it "It checks that need-label is not outputted." do
118
+ doc = Nokogiri::HTML(page.html)
119
+ label = doc.xpath("//label[@for='user_age']")
120
+ label[0]["class"].should be_nil
121
+ end
122
+ end
123
+
124
+ describe "instance variable type with class" do
125
+ before do
126
+ class UsersController < ApplicationController
127
+ def new
128
+ @user = User.new
129
+ render :inline => <<-ERB
130
+ <%= form_for @user do |f| %>
131
+ <%= f.label :name, :class => "foo" %>
132
+ <%= f.text_field :name %>
133
+ <%= f.label :age %>
134
+ <%= f.text_field :age %>
135
+ <%= f.submit "save" %>
136
+ <% end %>
137
+ ERB
138
+ end
139
+ end
140
+ visit "/users/new"
141
+ end
142
+ it "It checks that need-label is outputted." do
143
+ doc = Nokogiri::HTML(page.html)
144
+ label = doc.xpath("//label[@for='user_name']")
145
+ label[0]["class"].should == "foo need-label"
146
+ end
147
+ it "It checks that need-label is not outputted." do
148
+ doc = Nokogiri::HTML(page.html)
149
+ label = doc.xpath("//label[@for='user_age']")
150
+ label[0]["class"].should be_nil
151
+ end
152
+ end
153
+
154
+ describe "symbol type with class" do
155
+ before do
156
+ class UsersController < ApplicationController
157
+ def new
158
+ @user = User.new
159
+ render :inline => <<-ERB
160
+ <%= form_for :user do |f| %>
161
+ <%= f.label :name, :class => "foo" %>
162
+ <%= f.text_field :name %>
163
+ <%= f.label :age %>
164
+ <%= f.text_field :age %>
165
+ <%= f.submit "save" %>
166
+ <% end %>
167
+ ERB
168
+ end
169
+ end
170
+ visit "/users/new"
171
+ end
172
+ it "It checks that need-label is outputted." do
173
+ doc = Nokogiri::HTML(page.html)
174
+ label = doc.xpath("//label[@for='user_name']")
175
+ label[0]["class"].should == "foo need-label"
176
+ end
177
+ it "It checks that need-label is not outputted." do
178
+ doc = Nokogiri::HTML(page.html)
179
+ label = doc.xpath("//label[@for='user_age']")
180
+ label[0]["class"].should be_nil
181
+ end
182
+ end
183
+
184
+ describe "instance variable type with class and hidden options" do
185
+ before do
186
+ class UsersController < ApplicationController
187
+ def new
188
+ @user = User.new
189
+ render :inline => <<-ERB
190
+ <%= form_for @user do |f| %>
191
+ <%= f.label :name, :class => "foo", :need_label => false %>
192
+ <%= f.text_field :name %>
193
+ <%= f.label :age %>
194
+ <%= f.text_field :age %>
195
+ <%= f.submit "save" %>
196
+ <% end %>
197
+ ERB
198
+ end
199
+ end
200
+ visit "/users/new"
201
+ end
202
+ it "It checks that need-label is outputted." do
203
+ doc = Nokogiri::HTML(page.html)
204
+ label = doc.xpath("//label[@for='user_name']")
205
+ label[0]["class"].should == "foo"
206
+ end
207
+ it "It checks that need-label is not outputted." do
208
+ doc = Nokogiri::HTML(page.html)
209
+ label = doc.xpath("//label[@for='user_age']")
210
+ label[0]["class"].should be_nil
211
+ end
212
+ end
213
+
214
+ describe "symbol type with class and hidden options" do
215
+ before do
216
+ class UsersController < ApplicationController
217
+ def new
218
+ @user = User.new
219
+ render :inline => <<-ERB
220
+ <%= form_for :user do |f| %>
221
+ <%= f.label :name, :class => "foo", :need_label => false %>
222
+ <%= f.text_field :name %>
223
+ <%= f.label :age %>
224
+ <%= f.text_field :age %>
225
+ <%= f.submit "save" %>
226
+ <% end %>
227
+ ERB
228
+ end
229
+ end
230
+ visit "/users/new"
231
+ end
232
+ it "It checks that need-label is outputted." do
233
+ doc = Nokogiri::HTML(page.html)
234
+ label = doc.xpath("//label[@for='user_name']")
235
+ label[0]["class"].should == "foo"
236
+ end
237
+ it "It checks that need-label is not outputted." do
238
+ doc = Nokogiri::HTML(page.html)
239
+ label = doc.xpath("//label[@for='user_age']")
240
+ label[0]["class"].should be_nil
241
+ end
242
+ end
243
+ end
@@ -0,0 +1,19 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rails'
4
+ require 'rspec'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+ require File.join(File.dirname(__FILE__), 'fake_app')
10
+
11
+ require 'capybara/rails'
12
+ require 'rspec/rails'
13
+
14
+ RSpec.configure do |config|
15
+ config.mock_with :rr
16
+ config.before :all do
17
+ CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'users'
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: need_label
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yamamoto Kazuhisa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-31 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70293893131120 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.7
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70293893131120
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70293893130080 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.7.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70293893130080
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70293893129300 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70293893129300
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &70293893128300 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70293893128300
58
+ - !ruby/object:Gem::Dependency
59
+ name: rcov
60
+ requirement: &70293893127300 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70293893127300
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: &70293893125760 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.3.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70293893125760
80
+ - !ruby/object:Gem::Dependency
81
+ name: rspec-rails
82
+ requirement: &70293893123600 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 2.7.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70293893123600
91
+ - !ruby/object:Gem::Dependency
92
+ name: capybara
93
+ requirement: &70293893121800 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: 1.1.0
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70293893121800
102
+ - !ruby/object:Gem::Dependency
103
+ name: nokogiri
104
+ requirement: &70293893120520 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.5.0
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70293893120520
113
+ description: A class is outputted about an indispensable input item.
114
+ email: ak.hisashi@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files:
118
+ - LICENSE.txt
119
+ - README.rdoc
120
+ files:
121
+ - .document
122
+ - .rspec
123
+ - Gemfile
124
+ - Gemfile.lock
125
+ - LICENSE.txt
126
+ - README.rdoc
127
+ - Rakefile
128
+ - VERSION
129
+ - lib/need_label.rb
130
+ - lib/need_label/helpers.rb
131
+ - need_label.gemspec
132
+ - spec/fake_app.rb
133
+ - spec/requests/need_label_spec.rb
134
+ - spec/spec_helper.rb
135
+ homepage: http://github.com/kazuhisa/need_label
136
+ licenses:
137
+ - MIT
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ segments:
149
+ - 0
150
+ hash: 2346378593694578270
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 1.8.6
160
+ signing_key:
161
+ specification_version: 3
162
+ summary: output need-label
163
+ test_files: []