has_defaults 0.4.4 → 1.0.0

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.
data/.travis.yml DELETED
@@ -1,56 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 1.8.7
5
- - 2.1.8
6
- - 2.2.4
7
- - 2.3.1
8
-
9
- gemfile:
10
- - gemfiles/Gemfile.2.3.mysql2
11
- - gemfiles/Gemfile.3.2.mysql2
12
- - gemfiles/Gemfile.4.2.mysql2
13
- - gemfiles/Gemfile.4.2.pg
14
- - gemfiles/Gemfile.5.0.mysql2
15
- - gemfiles/Gemfile.5.0.pg
16
-
17
- matrix:
18
- exclude:
19
- - rvm: 1.8.7
20
- gemfile: gemfiles/Gemfile.4.2.mysql2
21
- - rvm: 1.8.7
22
- gemfile: gemfiles/Gemfile.4.2.pg
23
- - rvm: 1.8.7
24
- gemfile: gemfiles/Gemfile.5.0.mysql2
25
- - rvm: 1.8.7
26
- gemfile: gemfiles/Gemfile.5.0.pg
27
- - rvm: 2.1.8
28
- gemfile: gemfiles/Gemfile.2.3.mysql2
29
- - rvm: 2.1.8
30
- gemfile: gemfiles/Gemfile.5.0.mysql2
31
- - rvm: 2.1.8
32
- gemfile: gemfiles/Gemfile.5.0.pg
33
- - rvm: 2.2.4
34
- gemfile: gemfiles/Gemfile.2.3.mysql2
35
- - rvm: 2.3.1
36
- gemfile: gemfiles/Gemfile.2.3.mysql2
37
-
38
- install:
39
- # Old Travis CI bundler explodes when lockfile version doesn't match recently bumped version
40
- - gem install bundler --version='=1.12.5'
41
- # This is the default Travis CI install step
42
- - bundle install --jobs=3 --retry=3 --deployment --path=${BUNDLE_PATH:-vendor/bundle}
43
-
44
- before_script:
45
- - psql -c 'create database has_defaults_test;' -U postgres
46
- - mysql -e 'create database IF NOT EXISTS has_defaults_test;'
47
-
48
- script: bundle exec rake gemika:spec
49
-
50
- sudo: false
51
-
52
- cache: bundler
53
-
54
- notifications:
55
- email:
56
- - fail@makandra.de
@@ -1,13 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activerecord', '=2.3.18'
4
- gem 'rspec', '~> 1.3.0'
5
- gem 'mysql2', '= 0.2.20'
6
-
7
- gem 'rake', '=10.0.4'
8
-
9
- gem 'i18n', '=0.6.11' # 0.7 no longer builds for Ruby 1.8.7
10
-
11
- gem 'gemika', '>= 0.2.0'
12
- gem 'has_defaults', :path => '..'
13
-
@@ -1,32 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- has_defaults (0.4.3)
5
- activerecord
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activerecord (2.3.18)
11
- activesupport (= 2.3.18)
12
- activesupport (2.3.18)
13
- gemika (0.2.0)
14
- i18n (0.6.11)
15
- mysql2 (0.2.20)
16
- rake (10.0.4)
17
- rspec (1.3.2)
18
-
19
- PLATFORMS
20
- ruby
21
-
22
- DEPENDENCIES
23
- activerecord (= 2.3.18)
24
- gemika (>= 0.2.0)
25
- has_defaults!
26
- i18n (= 0.6.11)
27
- mysql2 (= 0.2.20)
28
- rake (= 10.0.4)
29
- rspec (~> 1.3.0)
30
-
31
- BUNDLED WITH
32
- 1.12.5
@@ -1,12 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activerecord', '=3.2.22'
4
- gem 'rspec', '~> 3.4'
5
- gem 'mysql2', '= 0.3.17'
6
-
7
- gem 'rake', '=10.0.4'
8
-
9
- gem 'i18n', '=0.6.11' # 0.7 no longer builds for Ruby 1.8.7
10
-
11
- gem 'gemika', '>= 0.2.0'
12
- gem 'has_defaults', :path => '..'
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activerecord', '~>4.2.1'
4
- gem 'rspec', '~>3.4'
5
- gem 'mysql2', '~> 0.3.17'
6
-
7
- gem 'rake'
8
-
9
- gem 'gemika', '>= 0.2.0'
10
- gem 'has_defaults', path: '..'
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activerecord', '~>4.2.1'
4
- gem 'rspec', '~>3.4'
5
- gem 'pg'
6
-
7
- gem 'rake'
8
-
9
- gem 'gemika', '>= 0.2.0'
10
- gem 'has_defaults', path: '..'
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activerecord', '~>5.0.0'
4
- gem 'rspec', '~>3.5'
5
- gem 'mysql2', '~>0.4.4'
6
-
7
- gem 'rake'
8
-
9
- gem 'gemika', '>= 0.2.0'
10
- gem 'has_defaults', path: '..'
@@ -1,10 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activerecord', '~>5.0.0'
4
- gem 'rspec', '~>3.5'
5
- gem 'pg', '~>0.18.4'
6
-
7
- gem 'rake'
8
-
9
- gem 'gemika', '>= 0.2.0'
10
- gem 'has_defaults', path: '..'
@@ -1,58 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- has_defaults (0.4.3)
5
- activerecord
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (5.0.0.1)
11
- activesupport (= 5.0.0.1)
12
- activerecord (5.0.0.1)
13
- activemodel (= 5.0.0.1)
14
- activesupport (= 5.0.0.1)
15
- arel (~> 7.0)
16
- activesupport (5.0.0.1)
17
- concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (~> 0.7)
19
- minitest (~> 5.1)
20
- tzinfo (~> 1.1)
21
- arel (7.1.2)
22
- concurrent-ruby (1.0.2)
23
- diff-lcs (1.2.5)
24
- gemika (0.2.0)
25
- i18n (0.7.0)
26
- minitest (5.9.0)
27
- pg (0.18.4)
28
- rake (11.3.0)
29
- rspec (3.5.0)
30
- rspec-core (~> 3.5.0)
31
- rspec-expectations (~> 3.5.0)
32
- rspec-mocks (~> 3.5.0)
33
- rspec-core (3.5.3)
34
- rspec-support (~> 3.5.0)
35
- rspec-expectations (3.5.0)
36
- diff-lcs (>= 1.2.0, < 2.0)
37
- rspec-support (~> 3.5.0)
38
- rspec-mocks (3.5.0)
39
- diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.5.0)
41
- rspec-support (3.5.0)
42
- thread_safe (0.3.5)
43
- tzinfo (1.2.2)
44
- thread_safe (~> 0.1)
45
-
46
- PLATFORMS
47
- ruby
48
-
49
- DEPENDENCIES
50
- activerecord (~> 5.0.0)
51
- gemika (>= 0.2.0)
52
- has_defaults!
53
- pg (~> 0.18.4)
54
- rake
55
- rspec (~> 3.5)
56
-
57
- BUNDLED WITH
58
- 1.12.5
@@ -1,105 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe HasDefaults::ActiveRecordExt do
4
-
5
- context "given a model with defaults" do
6
-
7
- describe 'initialization' do
8
-
9
- it "should set defaults" do
10
- new_donut = Donut.new
11
- new_donut.flavor.should == "cream"
12
- new_donut.name.should == "Cream"
13
- end
14
-
15
- it "should use setters methods to set the defaults" do
16
- new_donut = Donut.new
17
- new_donut.instance_variable_get('@flavor_setter_called').should == true
18
- end
19
-
20
- it "should call procs in the model context when given as defaults" do
21
- new_donut = Donut.new
22
- new_donut.weight.should == 'a lot'
23
- end
24
-
25
- it "should merge multiple has_defaults directives" do
26
- new_donut = Donut.new
27
- new_donut.flavor.should == "cream"
28
- new_donut.maker.should == "Dunkin Donuts"
29
- end
30
-
31
- it 'should not assign attributes multiple times when there are multiple has_defaults directives (bugfix)' do
32
- Donut.should_receive(:global_health_benefits).once
33
- Donut.new
34
- end
35
-
36
- it "should set defaults only if attributes are nil" do
37
- donut = Donut.new(:flavor => 'vanilla')
38
- donut.flavor.should == "vanilla"
39
- end
40
-
41
- it "should not set a default on an attribute that is set to an empty string" do
42
- donut = Donut.new(:flavor => '')
43
- donut.flavor.should == ''
44
- end
45
-
46
- it "should use getters methods to check if an attribute is nil" do
47
- new_donut = Donut.new
48
- new_donut.instance_variable_get('@flavor_getter_called').should == true
49
- end
50
-
51
- it "should return default value for an attribute" do
52
- Donut.new.default_for(:flavor).should == "cream"
53
- end
54
-
55
- it "should not set defaults when loading a saved record" do
56
- Donut.create(:flavor => "vanilla")
57
- Donut.first.flavor.should == "vanilla"
58
- end
59
-
60
- it "should define #after_initialize in Rails 2, but not Rails 3 (this method must be defined so after_initialize callbacks run)" do
61
- donut = Donut.new
62
- if ActiveRecord::VERSION::MAJOR < 3
63
- donut.should respond_to(:after_initialize)
64
- else
65
- donut.should_not respond_to(:after_initialize)
66
- end
67
- end
68
-
69
- it "should not redefine defaults in its superclass" do
70
- pastry = Pastry.new
71
- pastry.maker.should == 'Mom'
72
- pastry.default_for(:maker).should == 'Mom'
73
- end
74
-
75
- it "should respect defaults from its superclass" do
76
- donut = Donut.create
77
- donut.main_ingredient.should == 'flour'
78
- donut.maker.should_not == 'Mom'
79
- end
80
-
81
- end
82
-
83
- describe '#default_for' do
84
-
85
- it "should return the default value for the given attribute" do
86
- Donut.new.default_for(:flavor).should == 'cream'
87
- end
88
-
89
- it 'should evaluate the default value if it is a lambda' do
90
- Donut.new.default_for(:weight).should == 'a lot'
91
- end
92
-
93
- end
94
-
95
- end
96
-
97
- context "given a model without defaults" do
98
-
99
- it "should not define #after_initialize so initialization remains fast" do
100
- ModelWithoutDefaults.new.should_not respond_to(:after_initialize)
101
- end
102
-
103
- end
104
-
105
- end
data/spec/spec_helper.rb DELETED
@@ -1,18 +0,0 @@
1
- $: << File.join(File.dirname(__FILE__), "/../../lib" )
2
-
3
- require 'has_defaults'
4
- require 'gemika'
5
-
6
- ActiveRecord::Base.default_timezone = :local
7
-
8
- Dir["#{File.dirname(__FILE__)}/support/*.rb"].sort.each {|f| require f}
9
- Dir["#{File.dirname(__FILE__)}/shared_examples/*.rb"].sort.each {|f| require f}
10
-
11
- Gemika::RSpec.configure_transactional_examples
12
-
13
- if Gemika::Env.rspec_2_plus?
14
- RSpec.configure do |config|
15
- config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
16
- config.mock_with(:rspec) { |c| c.syntax = [:should, :expect] }
17
- end
18
- end
@@ -1,16 +0,0 @@
1
- Gemika::Database.new.rewrite_schema! do
2
-
3
- create_table :pastries do |t|
4
- t.string :type
5
- t.string :flavor
6
- t.string :name
7
- t.string :maker
8
- t.string :weight
9
- t.string :main_ingredient
10
- t.string :health_benefits
11
- end
12
-
13
- create_table :model_without_defaults do |t|
14
- end
15
-
16
- end
@@ -1,10 +0,0 @@
1
- mysql:
2
- database: has_defaults_test
3
- host: localhost
4
- username: root
5
- password: secret
6
-
7
- postgresql:
8
- database: has_defaults_test
9
- user:
10
- password:
@@ -1,9 +0,0 @@
1
- mysql:
2
- database: has_defaults_test
3
- username: travis
4
- password:
5
-
6
- postgresql:
7
- database: has_defaults_test
8
- user: postgres
9
- password:
@@ -1,10 +0,0 @@
1
- mysql:
2
- database: has_defaults_test
3
- host: localhost
4
- username: root
5
- password: junior
6
-
7
- postgresql:
8
- database: has_defaults_test
9
- user:
10
- password:
@@ -1,37 +0,0 @@
1
- class Pastry < ActiveRecord::Base
2
-
3
- has_defaults :main_ingredient => "flour", :maker => "Mom"
4
-
5
- end
6
-
7
-
8
- class Donut < Pastry
9
-
10
- has_defaults :flavor => "cream", :name => "Cream"
11
- has_defaults :maker => lambda { "Dunkin Donuts" }
12
- has_defaults :weight => lambda { weigh }
13
- has_defaults :health_benefits => lambda { self.class.global_health_benefits }
14
-
15
- def flavor
16
- @flavor_getter_called = true
17
- read_attribute(:flavor)
18
- end
19
-
20
- def flavor=(value)
21
- @flavor_setter_called = true
22
- write_attribute(:flavor, value)
23
- end
24
-
25
- def weigh
26
- "a lot"
27
- end
28
-
29
- def self.global_health_benefits
30
- 'none'
31
- end
32
-
33
- end
34
-
35
-
36
- class ModelWithoutDefaults < ActiveRecord::Base
37
- end