star_it 0.0.1.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26d41177e86a7561d109cfbfd6594d918f6473a7
4
+ data.tar.gz: 31e07eeee2654d31cd89e81c6f44a0d4ca1225e2
5
+ SHA512:
6
+ metadata.gz: 01abd55f33e5f43114364532588ab4bfb3c20d02a8b69d90d9508e348fd01116b781f3087dd41ca92c2bcef29f8eb659d2e75e5e644cce2c90790a4201467776
7
+ data.tar.gz: b11714e3990bd58c54085a95adaebb9c6c699aef38e55bdee18dcb41daff8c6024a94fdc645941f71f918e1ae9c706caa49f167a54199b29f1c25b12ca7c1951
@@ -0,0 +1,11 @@
1
+ module ActionView
2
+ module Helpers
3
+ class FormBuilder
4
+ def label_with_star(method, text = nil, options = {}, &block)
5
+ options.merge!(class: "star_it #{options[:class]}") if StarRequiredFields.needed_for(@object.class.name, method)
6
+ label_without_star(method, text, options, &block)
7
+ end
8
+ alias_method_chain :label, :star
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class StarRequiredFields
2
+ def self.needed_for(model_name, field_name)
3
+ return false unless model_name.constantize.respond_to?(:table_name)
4
+
5
+ presence_validator = model_name.constantize.validators.select do |validator_instance|
6
+ validator_instance.is_a?(ActiveRecord::Validations::PresenceValidator)
7
+ end
8
+
9
+ presence_validator.collect{|validator| validator.attributes}.flatten.include?(field_name.to_sym)
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module StarIt
2
+ VERSION='0.0.1.2'
3
+ end
data/lib/star_it.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'rails'
2
+ require 'action_view'
3
+ require 'active_record'
4
+
5
+ require "star_it/version"
6
+ require "star_it/star_required_fields"
7
+ require "star_it/label_form_builder"
data/spec/db/schema.rb ADDED
@@ -0,0 +1,12 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+
3
+ create_table :projects, :force => true do |t|
4
+ t.string :title
5
+ t.text :summary
6
+ t.text :description
7
+ t.text :body
8
+ t.integer :views
9
+ end
10
+
11
+ end
12
+
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'LabelFormBuilder' do
4
+ before do
5
+ project_class = double('Project', name: 'Project')
6
+ @project = double('project', longname: 'Project', class: project_class)
7
+ @template = ActionView::Base.new
8
+ @parent_builder = ActionView::Helpers::FormBuilder.new(:project, @project, @template, {}, nil)
9
+ end
10
+
11
+ context 'required fields' do
12
+ before do
13
+ StarRequiredFields.should_receive(:needed_for).with('Project', :name).and_return(true)
14
+ end
15
+ it 'should add class star to label tag if no class is present' do
16
+ expect(@parent_builder.label(:name)).to eq('<label class="star_it " for="project_name">Name</label>')
17
+ end
18
+
19
+ it 'should append star class to existing class' do
20
+ expect(@parent_builder.label(:name, 'title', class: 'title')).to eq('<label class="star_it title" for="project_name">title</label>')
21
+ end
22
+ end
23
+
24
+ context 'not required fields' do
25
+ it 'should add class star to label tag if no class is present' do
26
+ StarRequiredFields.should_receive(:needed_for).with('Project', :name).and_return(false)
27
+ expect(@parent_builder.label(:name)).to eq('<label for="project_name">Name</label>')
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ require 'star_it'
2
+
3
+ config = YAML::load(IO.read(File.join(File.dirname(__FILE__), 'db', 'database.yml')))
4
+ ActiveRecord::Base.configurations = {'test' => config[ENV['DB'] || 'sqlite3']}
5
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['test'])
6
+
7
+ # Load Test Schema into the Database
8
+ load(File.dirname(__FILE__) + "/db/schema.rb")
9
+
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'StarRequiredFields' do
4
+ before do
5
+ class Project < ActiveRecord::Base
6
+ validates_presence_of :title
7
+ validates_presence_of :description
8
+ end
9
+
10
+ class SubProject < Project
11
+ validates_presence_of :body
12
+ end
13
+ end
14
+ it 'should return list of star_required_fields for a given model' do
15
+ expect(StarRequiredFields.needed_for("Project", "title")).to be_true
16
+ expect(StarRequiredFields.needed_for("Project", "description")).to be_true
17
+ expect(StarRequiredFields.needed_for("Project", "summary")).to be_false
18
+ end
19
+
20
+ it 'should return false if table does not exist' do
21
+ expect(StarRequiredFields.needed_for("OpenStruct", "name")).to be_false
22
+ end
23
+
24
+ it 'should validate for inherited models' do
25
+ expect(StarRequiredFields.needed_for("SubProject", "body")).to be_true
26
+ expect(StarRequiredFields.needed_for("SubProject", "description")).to be_true
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: star_it
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Deepthi
8
+ - Senthil
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: sqlite3
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rails
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '='
47
+ - !ruby/object:Gem::Version
48
+ version: 4.0.0
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '='
54
+ - !ruby/object:Gem::Version
55
+ version: 4.0.0
56
+ description: A gem to add class mandatory to model required fields
57
+ email: deepthirera@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/star_it/label_form_builder.rb
63
+ - lib/star_it/star_required_fields.rb
64
+ - lib/star_it/version.rb
65
+ - lib/star_it.rb
66
+ - spec/db/schema.rb
67
+ - spec/label_form_builder_spec.rb
68
+ - spec/spec_helper.rb
69
+ - spec/star_required_fields_spec.rb
70
+ homepage: https://github.com/deepthirera/star_it.git
71
+ licenses: []
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.0.3
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Gem to add required star_it for view fields
93
+ test_files:
94
+ - spec/db/schema.rb
95
+ - spec/label_form_builder_spec.rb
96
+ - spec/spec_helper.rb
97
+ - spec/star_required_fields_spec.rb