acts_as_defaultable 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.rspec +1 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +145 -0
- data/Guardfile +19 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +29 -0
- data/Rakefile +27 -0
- data/acts_as_defaultable.gemspec +32 -0
- data/lib/acts_as_defaultable/version.rb +3 -0
- data/lib/acts_as_defaultable.rb +77 -0
- data/lib/tasks/acts_as_defaultable_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/another.rb +7 -0
- data/spec/dummy/app/models/boolean_default.rb +3 -0
- data/spec/dummy/app/models/fail_one.rb +3 -0
- data/spec/dummy/app/models/string_default.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +62 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +42 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20120103170153_create_anothers.rb +9 -0
- data/spec/dummy/db/migrate/20120104112622_create_fail_ones.rb +11 -0
- data/spec/dummy/db/migrate/20120104135210_create_boolean_defaults.rb +9 -0
- data/spec/dummy/db/migrate/20120104140205_create_string_defaults.rb +10 -0
- data/spec/dummy/db/schema.rb +44 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/another.rb +11 -0
- data/spec/factories/boolean_default.rb +11 -0
- data/spec/factories/fail_one.rb +6 -0
- data/spec/factories/string_default.rb +11 -0
- data/spec/models/another_spec.rb +58 -0
- data/spec/models/boolean_default_spec.rb +57 -0
- data/spec/models/fail_one_spec.rb +5 -0
- data/spec/models/string_default_spec.rb +56 -0
- data/spec/spec_helper.rb +82 -0
- metadata +193 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Another do
|
4
|
+
|
5
|
+
let(:another) { FactoryGirl.build(:another) }
|
6
|
+
let(:other) { FactoryGirl.build(:other) }
|
7
|
+
|
8
|
+
it 'should have a class method named default' do
|
9
|
+
Another.respond_to?('default').should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should have a default column definition' do
|
13
|
+
Another.respond_to?('default_column').should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return the argument as the default column' do
|
17
|
+
Another.default_column.should be_eql('unique')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have a default positive value' do
|
21
|
+
Another.default_positive_value.should be_eql(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have a default negative value' do
|
25
|
+
Another.default_negative_value.should be_eql(0)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should return nil if there is no default object' do
|
29
|
+
another.unique = 0
|
30
|
+
another.save
|
31
|
+
Another.default.should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should return a default object' do
|
35
|
+
another.unique = 1
|
36
|
+
another.save
|
37
|
+
Another.default.should be_eql(another)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should set unique default object' do
|
41
|
+
other.unique = 1
|
42
|
+
other.save
|
43
|
+
another.unique = 1
|
44
|
+
another.save
|
45
|
+
Another.default.should be_eql(another)
|
46
|
+
#other.unique.should be_eql(0)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should return all defaults' do
|
50
|
+
another.unique = 1
|
51
|
+
another.save
|
52
|
+
other.unique = 1
|
53
|
+
other.save
|
54
|
+
Another.all_defaults.size.should be_eql(1)
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BooleanDefault do
|
4
|
+
|
5
|
+
let(:one) { FactoryGirl.build(:boolean_default) }
|
6
|
+
let(:two) { FactoryGirl.build(:true_boolean_default) }
|
7
|
+
|
8
|
+
it 'should have a class method named default' do
|
9
|
+
BooleanDefault.respond_to?('default').should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should have a default column definition' do
|
13
|
+
BooleanDefault.respond_to?('default_column').should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return the argument as the default column' do
|
17
|
+
BooleanDefault.default_column.should be_eql('default')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have a default positive value' do
|
21
|
+
BooleanDefault.default_positive_value.should be_eql(true)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have a default negative value' do
|
25
|
+
BooleanDefault.default_negative_value.should be_eql(false)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should return nil if there is no default object' do
|
29
|
+
one.default = false
|
30
|
+
one.save
|
31
|
+
BooleanDefault.default.should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should return a default object' do
|
35
|
+
one.default = true
|
36
|
+
one.save
|
37
|
+
BooleanDefault.default.should be_eql(one)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should set unique default object' do
|
41
|
+
two.default = true
|
42
|
+
two.save
|
43
|
+
one.default = true
|
44
|
+
two.save
|
45
|
+
BooleanDefault.default.should be_eql(two)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should return all defaults' do
|
49
|
+
one.default = true
|
50
|
+
one.save
|
51
|
+
two.default = true
|
52
|
+
two.save
|
53
|
+
BooleanDefault.all_defaults.size.should be_eql(1)
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StringDefault do
|
4
|
+
|
5
|
+
let(:one) { FactoryGirl.build(:string_default) }
|
6
|
+
let(:two) { FactoryGirl.build(:true_string_default) }
|
7
|
+
|
8
|
+
it 'should have a class method named default' do
|
9
|
+
StringDefault.respond_to?('default').should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should have a default column definition' do
|
13
|
+
StringDefault.respond_to?('default_column').should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return the argument as the default column' do
|
17
|
+
StringDefault.default_column.should be_eql('default')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have a default positive value' do
|
21
|
+
StringDefault.default_positive_value.should be_eql("on")
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have a default negative value' do
|
25
|
+
StringDefault.default_negative_value.should be_eql('off')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should return nil if there is no default object' do
|
29
|
+
one.default = 'off'
|
30
|
+
one.save
|
31
|
+
StringDefault.default.should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should return a default object' do
|
35
|
+
one.default = 'on'
|
36
|
+
one.save
|
37
|
+
StringDefault.default.should be_eql(one)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should set unique default object' do
|
41
|
+
two.default = 'on'
|
42
|
+
two.save
|
43
|
+
one.default = 'on'
|
44
|
+
two.save
|
45
|
+
StringDefault.default.should be_eql(two)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should return all defaults' do
|
49
|
+
one.default = 'on'
|
50
|
+
one.save
|
51
|
+
two.default = 'on'
|
52
|
+
two.save
|
53
|
+
StringDefault.all_defaults.size.should be_eql(1)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spork'
|
3
|
+
require 'factory_girl'
|
4
|
+
require 'database_cleaner'
|
5
|
+
|
6
|
+
Spork.prefork do
|
7
|
+
# Loading more in this block will cause your tests to run faster. However,
|
8
|
+
# if you change any configuration or code from libraries loaded here, you'll
|
9
|
+
# need to restart spork for it take effect.
|
10
|
+
ENV["RAILS_ENV"] ||= 'test'
|
11
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
12
|
+
|
13
|
+
require 'rspec/rails'
|
14
|
+
require 'rspec/autorun'
|
15
|
+
|
16
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
17
|
+
# in spec/support/ and its subdirectories.
|
18
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
# == Mock Framework
|
22
|
+
#
|
23
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
24
|
+
#
|
25
|
+
# config.mock_with :mocha
|
26
|
+
# config.mock_with :flexmock
|
27
|
+
# config.mock_with :rr
|
28
|
+
config.mock_with :rspec
|
29
|
+
|
30
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
31
|
+
# examples within a transaction, remove the following line or assign false
|
32
|
+
# instead of true.
|
33
|
+
config.use_transactional_fixtures = false
|
34
|
+
|
35
|
+
# If true, the base class of anonymous controllers will be inferred
|
36
|
+
# automatically. This will be the default behavior in future versions of
|
37
|
+
# rspec-rails.
|
38
|
+
config.infer_base_class_for_anonymous_controllers = false
|
39
|
+
|
40
|
+
config.use_instantiated_fixtures = false
|
41
|
+
|
42
|
+
# Use DatabaseCleaner to enable js testing
|
43
|
+
config.before(:suite) do
|
44
|
+
DatabaseCleaner.strategy = :truncation
|
45
|
+
DatabaseCleaner.clean_with(:truncation)
|
46
|
+
end
|
47
|
+
|
48
|
+
config.before(:each) do
|
49
|
+
#Timecop.return
|
50
|
+
DatabaseCleaner.start
|
51
|
+
end
|
52
|
+
|
53
|
+
config.after(:each) do
|
54
|
+
DatabaseCleaner.clean
|
55
|
+
end
|
56
|
+
|
57
|
+
config.before(:all) do
|
58
|
+
#DeferredGarbageCollection.start
|
59
|
+
end
|
60
|
+
|
61
|
+
config.after(:all) do
|
62
|
+
#DeferredGarbageCollection.reconsider
|
63
|
+
end
|
64
|
+
|
65
|
+
# Add helpers for devise authentication
|
66
|
+
#config.include Devise::TestHelpers, type: :controller
|
67
|
+
#config.extend ControllerMacros, type: :controller
|
68
|
+
|
69
|
+
# Also include warden
|
70
|
+
#config.include Warden::Test::Helpers
|
71
|
+
#config.after(:each) { Warden.test_reset!}
|
72
|
+
|
73
|
+
# Include factory_girl's helpers
|
74
|
+
#config.include FactoryGirl::Syntax::Methods
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
Spork.each_run do
|
79
|
+
#FactoryGirl.reload
|
80
|
+
FactoryGirl.find_definitions
|
81
|
+
end
|
82
|
+
|
metadata
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_defaultable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Giorgos Tsiftsis
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &20379900 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.0.rc1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *20379900
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mysql2
|
27
|
+
requirement: &20378580 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *20378580
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: factory_girl_rails
|
38
|
+
requirement: &20377300 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *20377300
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: spork
|
49
|
+
requirement: &20392860 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - =
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.0.rc9
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *20392860
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rb-fsevent
|
60
|
+
requirement: &20391940 !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: *20391940
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: &20390400 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *20390400
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: libnotify
|
82
|
+
requirement: &20388840 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *20388840
|
91
|
+
description: This 'acts_as' extension provides the capability for having a default
|
92
|
+
object. The class that has this specified needs to have a default column defined
|
93
|
+
as an integer, string or boolean on the mapped database table
|
94
|
+
email:
|
95
|
+
- giorgos.tsiftsis@gmail.com
|
96
|
+
executables: []
|
97
|
+
extensions: []
|
98
|
+
extra_rdoc_files: []
|
99
|
+
files:
|
100
|
+
- .gitignore
|
101
|
+
- .rspec
|
102
|
+
- Gemfile
|
103
|
+
- Gemfile.lock
|
104
|
+
- Guardfile
|
105
|
+
- MIT-LICENSE
|
106
|
+
- README.rdoc
|
107
|
+
- Rakefile
|
108
|
+
- acts_as_defaultable.gemspec
|
109
|
+
- lib/acts_as_defaultable.rb
|
110
|
+
- lib/acts_as_defaultable/version.rb
|
111
|
+
- lib/tasks/acts_as_defaultable_tasks.rake
|
112
|
+
- spec/dummy/README.rdoc
|
113
|
+
- spec/dummy/Rakefile
|
114
|
+
- spec/dummy/app/assets/javascripts/application.js
|
115
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
116
|
+
- spec/dummy/app/controllers/application_controller.rb
|
117
|
+
- spec/dummy/app/helpers/application_helper.rb
|
118
|
+
- spec/dummy/app/mailers/.gitkeep
|
119
|
+
- spec/dummy/app/models/.gitkeep
|
120
|
+
- spec/dummy/app/models/another.rb
|
121
|
+
- spec/dummy/app/models/boolean_default.rb
|
122
|
+
- spec/dummy/app/models/fail_one.rb
|
123
|
+
- spec/dummy/app/models/string_default.rb
|
124
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
125
|
+
- spec/dummy/config.ru
|
126
|
+
- spec/dummy/config/application.rb
|
127
|
+
- spec/dummy/config/boot.rb
|
128
|
+
- spec/dummy/config/database.yml
|
129
|
+
- spec/dummy/config/environment.rb
|
130
|
+
- spec/dummy/config/environments/development.rb
|
131
|
+
- spec/dummy/config/environments/production.rb
|
132
|
+
- spec/dummy/config/environments/test.rb
|
133
|
+
- spec/dummy/config/initializers/backtrace_silencers.rb
|
134
|
+
- spec/dummy/config/initializers/inflections.rb
|
135
|
+
- spec/dummy/config/initializers/mime_types.rb
|
136
|
+
- spec/dummy/config/initializers/secret_token.rb
|
137
|
+
- spec/dummy/config/initializers/session_store.rb
|
138
|
+
- spec/dummy/config/initializers/wrap_parameters.rb
|
139
|
+
- spec/dummy/config/locales/en.yml
|
140
|
+
- spec/dummy/config/routes.rb
|
141
|
+
- spec/dummy/db/migrate/20120103170153_create_anothers.rb
|
142
|
+
- spec/dummy/db/migrate/20120104112622_create_fail_ones.rb
|
143
|
+
- spec/dummy/db/migrate/20120104135210_create_boolean_defaults.rb
|
144
|
+
- spec/dummy/db/migrate/20120104140205_create_string_defaults.rb
|
145
|
+
- spec/dummy/db/schema.rb
|
146
|
+
- spec/dummy/lib/assets/.gitkeep
|
147
|
+
- spec/dummy/log/.gitkeep
|
148
|
+
- spec/dummy/public/404.html
|
149
|
+
- spec/dummy/public/422.html
|
150
|
+
- spec/dummy/public/500.html
|
151
|
+
- spec/dummy/public/favicon.ico
|
152
|
+
- spec/dummy/script/rails
|
153
|
+
- spec/factories/another.rb
|
154
|
+
- spec/factories/boolean_default.rb
|
155
|
+
- spec/factories/fail_one.rb
|
156
|
+
- spec/factories/string_default.rb
|
157
|
+
- spec/models/another_spec.rb
|
158
|
+
- spec/models/boolean_default_spec.rb
|
159
|
+
- spec/models/fail_one_spec.rb
|
160
|
+
- spec/models/string_default_spec.rb
|
161
|
+
- spec/spec_helper.rb
|
162
|
+
homepage: https://github.com/chief/acts_as_defaultable
|
163
|
+
licenses: []
|
164
|
+
post_install_message:
|
165
|
+
rdoc_options: []
|
166
|
+
require_paths:
|
167
|
+
- lib
|
168
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
segments:
|
175
|
+
- 0
|
176
|
+
hash: -2181701582938648428
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
|
+
none: false
|
179
|
+
requirements:
|
180
|
+
- - ! '>='
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
segments:
|
184
|
+
- 0
|
185
|
+
hash: -2181701582938648428
|
186
|
+
requirements: []
|
187
|
+
rubyforge_project:
|
188
|
+
rubygems_version: 1.8.10
|
189
|
+
signing_key:
|
190
|
+
specification_version: 3
|
191
|
+
summary: A gem allowing an active_record model to be default(unique) based on a specified
|
192
|
+
column
|
193
|
+
test_files: []
|