automatic_record 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40acbf709da113d0bf43a47c07d6bec14844f870
4
- data.tar.gz: 978030fe910a4f7423496fe0d9a0d012a572e5b2
3
+ metadata.gz: 12dcf108b424c2704cf0e8850ecfa6da84076f0c
4
+ data.tar.gz: 72c1f43594b34489fdc22500f4969c8f66c27cde
5
5
  SHA512:
6
- metadata.gz: 984c40283762c8dc41218d30cd9d1f78dff321fa7f09fc3ad9341af505240f3f0e63a3441eb5eef93a5c4882038e829d66a0a023a584c5df22eebb532d01419b
7
- data.tar.gz: 0e666081ee81d57227bf47469efb50f5c0b0df5bc228fb33d9da7334313fc8b05cdc2065d1fc35ed9b7df479f9e6d790b01a62b6a59bdb3484f9864164b16be7
6
+ metadata.gz: ba76de7cc5a42b4d1a77cc7009970b77797fab29db4773d3f160f3ee3fc725491feea382f055a5b5b048e0be985d678fe0b89a75cefe902a2b4c3cb591aee20f
7
+ data.tar.gz: c0bfa1287c95b0de9223c8a4ea01b36c84d39dcf55d3840c94854b208a6e3ed7efd556d2f3573ae608909e2b6a0809d3a53c78492c9497652cbaf1690be09191
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
17
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
18
18
  load 'rails/tasks/engine.rake'
19
19
 
20
20
  Bundler::GemHelper.install_tasks
@@ -27,30 +27,30 @@ module AutomaticRecord
27
27
  # Pass a block to be used for object creation:
28
28
  # auto_create :preference, ->(user){ user.create_preference(:language => 'en', :notifications => true) }
29
29
  #
30
- def auto_create(assoc, default_attrs_or_block={})
30
+ def auto_create(assoc, default_attrs_or_block = {})
31
31
  reflection = reflect_on_association(assoc)
32
32
  if reflection.nil?
33
- raise AutomaticRecord::Error::MissingAssociation.new(assoc)
33
+ raise AutomaticRecord::Error::MissingAssociation, assoc
34
34
  elsif !(reflection.has_one? || reflection.belongs_to?)
35
- raise AutomaticRecord::Error::InvalidAssociation.new(assoc)
35
+ raise AutomaticRecord::Error::InvalidAssociation, assoc
36
36
  else
37
- define_method(assoc) do |force_reload=false|
38
- return get_or_auto_create_assoc(assoc, force_reload, default_attrs_or_block)
37
+ define_method(assoc) do |_force_reload = nil| # force_reload is deprecated by rails
38
+ return get_or_auto_create_assoc(assoc, default_attrs_or_block)
39
39
  end
40
40
  end
41
41
  end
42
42
  end
43
43
 
44
- private
44
+ private
45
45
 
46
- def get_or_auto_create_assoc(assoc, force_reload=false, default_attrs_or_block={}) # :nodoc:
47
- result = method(assoc).super_method.call(force_reload)
46
+ def get_or_auto_create_assoc(assoc, default_attrs_or_block = {}) # :nodoc:
47
+ result = method(assoc).super_method.call
48
48
  if result.blank?
49
- if default_attrs_or_block.is_a?(Proc)
50
- result = default_attrs_or_block.call(self)
51
- else
52
- result = send("create_#{assoc}", default_attrs_or_block)
53
- end
49
+ result = if default_attrs_or_block.is_a?(Proc)
50
+ default_attrs_or_block.call(self)
51
+ else
52
+ send("create_#{assoc}", default_attrs_or_block)
53
+ end
54
54
  end
55
55
  return result
56
56
  end
@@ -5,7 +5,7 @@ module AutomaticRecord
5
5
 
6
6
  config.generators do |g|
7
7
  g.test_framework :rspec
8
- g.fixture_replacement :factory_girl, :dir => 'spec/factories'
8
+ g.fixture_replacement :factory_girl, dir: 'spec/factories'
9
9
  end
10
10
 
11
11
  initializer 'automatic_record' do
@@ -1,3 +1,3 @@
1
1
  module AutomaticRecord
2
- VERSION = "0.0.2"
2
+ VERSION = '0.0.3'.freeze
3
3
  end
@@ -1,13 +1,13 @@
1
1
  class Preference < ActiveRecord::Base
2
2
 
3
3
  belongs_to :user
4
- belongs_to :user_with_default_attrs, :class_name => 'User', :foreign_key => 'user_id'
5
- belongs_to :user_with_block, :class_name => 'User', :foreign_key => 'user_id'
4
+ belongs_to :user_with_default_attrs, class_name: 'User', foreign_key: 'user_id'
5
+ belongs_to :user_with_block, class_name: 'User', foreign_key: 'user_id'
6
6
 
7
7
  auto_create :user
8
- auto_create :user_with_default_attrs, {:username => 'defaulted'}
9
- auto_create :user_with_block, ->(instance){
10
- instance.create_user(:username => 'blocked')
8
+ auto_create :user_with_default_attrs, username: 'defaulted'
9
+ auto_create :user_with_block, ->(instance) {
10
+ instance.create_user(username: 'blocked')
11
11
  }
12
12
 
13
13
  end
@@ -1,13 +1,13 @@
1
1
  class User < ActiveRecord::Base
2
2
 
3
3
  has_one :preference
4
- has_one :preference_with_default_attrs, :class_name => 'Preference'
5
- has_one :preference_with_block, :class_name => 'Preference'
4
+ has_one :preference_with_default_attrs, class_name: 'Preference'
5
+ has_one :preference_with_block, class_name: 'Preference'
6
6
 
7
7
  auto_create :preference
8
- auto_create :preference_with_default_attrs, {:language => 'en', :notifications => true}
9
- auto_create :preference_with_block, ->(instance){
10
- instance.create_preference(:language => 'fr', :notifications => true)
8
+ auto_create :preference_with_default_attrs, language: 'en', notifications: true
9
+ auto_create :preference_with_block, ->(instance) {
10
+ instance.create_preference(language: 'fr', notifications: true)
11
11
  }
12
12
 
13
13
  end
@@ -2,15 +2,15 @@
2
2
  require 'pathname'
3
3
 
4
4
  # path to your application root.
5
- APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
6
 
7
7
  Dir.chdir APP_ROOT do
8
8
  # This script is a starting point to setup your application.
9
9
  # Add necessary setup steps to this file:
10
10
 
11
- puts "== Installing dependencies =="
12
- system "gem install bundler --conservative"
13
- system "bundle check || bundle install"
11
+ puts '== Installing dependencies =='
12
+ system 'gem install bundler --conservative'
13
+ system 'bundle check || bundle install'
14
14
 
15
15
  # puts "\n== Copying sample files =="
16
16
  # unless File.exist?("config/database.yml")
@@ -18,12 +18,12 @@ Dir.chdir APP_ROOT do
18
18
  # end
19
19
 
20
20
  puts "\n== Preparing database =="
21
- system "bin/rake db:setup"
21
+ system 'bin/rake db:setup'
22
22
 
23
23
  puts "\n== Removing old logs and tempfiles =="
24
- system "rm -f log/*"
25
- system "rm -rf tmp/cache"
24
+ system 'rm -f log/*'
25
+ system 'rm -rf tmp/cache'
26
26
 
27
27
  puts "\n== Restarting application server =="
28
- system "touch tmp/restart.txt"
28
+ system 'touch tmp/restart.txt'
29
29
  end
@@ -3,7 +3,7 @@ require File.expand_path('../boot', __FILE__)
3
3
  require 'rails/all'
4
4
 
5
5
  Bundler.require(*Rails.groups)
6
- require "automatic_record"
6
+ require 'automatic_record'
7
7
 
8
8
  module Dummy
9
9
  class Application < Rails::Application
@@ -18,9 +18,5 @@ module Dummy
18
18
  # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
19
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
20
  # config.i18n.default_locale = :de
21
-
22
- # Do not swallow errors in after_commit/after_rollback callbacks.
23
- config.active_record.raise_in_transactional_callbacks = true
24
21
  end
25
22
  end
26
-
@@ -13,8 +13,8 @@ Rails.application.configure do
13
13
  config.eager_load = false
14
14
 
15
15
  # Configure static file server for tests with Cache-Control for performance.
16
- config.serve_static_files = true
17
- config.static_cache_control = 'public, max-age=3600'
16
+ config.public_file_server.enabled = true
17
+ config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
18
18
 
19
19
  # Show full error reports and disable caching.
20
20
  config.consider_all_requests_local = true
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # This file is auto-generated from the current state of the database. Instead
3
2
  # of editing this file, please use the migrations feature of Active Record to
4
3
  # incrementally modify your database, and then regenerate this schema definition.
@@ -13,18 +12,18 @@
13
12
 
14
13
  ActiveRecord::Schema.define(version: 20150416151003) do
15
14
 
16
- create_table "preferences", force: :cascade do |t|
17
- t.integer "user_id", limit: 4
18
- t.string "language", limit: 255
19
- t.boolean "notifications", limit: 1
20
- t.datetime "created_at", null: false
21
- t.datetime "updated_at", null: false
15
+ create_table "preferences", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
16
+ t.integer "user_id"
17
+ t.string "language"
18
+ t.boolean "notifications"
19
+ t.datetime "created_at", null: false
20
+ t.datetime "updated_at", null: false
22
21
  end
23
22
 
24
- create_table "users", force: :cascade do |t|
25
- t.string "username", limit: 255
26
- t.datetime "created_at", null: false
27
- t.datetime "updated_at", null: false
23
+ create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
24
+ t.string "username"
25
+ t.datetime "created_at", null: false
26
+ t.datetime "updated_at", null: false
28
27
  end
29
28
 
30
29
  end
@@ -5,14 +5,14 @@ RSpec.describe Preference, type: :model do
5
5
  describe '#belongs_to' do
6
6
  it 'should create the user record' do
7
7
  preference = FactoryGirl.create(:preference)
8
- expect{
8
+ expect do
9
9
  preference.user
10
- }.to change(User, :count).by(1)
10
+ end.to change(User, :count).by(1)
11
11
  end
12
12
 
13
13
  it 'should get the pre-existing record' do
14
14
  user = FactoryGirl.create(:user)
15
- preference = FactoryGirl.create(:preference, :user_id => user.id)
15
+ preference = FactoryGirl.create(:preference, user_id: user.id)
16
16
  expect(preference.user).to eq(user)
17
17
  end
18
18
 
@@ -27,17 +27,6 @@ RSpec.describe Preference, type: :model do
27
27
  user = preference.user_with_block
28
28
  expect(user.username).to eq('blocked')
29
29
  end
30
-
31
- it 'should reload the record from the database' do
32
- preference = FactoryGirl.create(:preference)
33
- user = preference.user
34
-
35
- user_alt = User.find_by(:id => user.id)
36
- user_alt.update_attribute(:username, 'reloaded')
37
-
38
- expect(preference.user.username).to_not eq('reloaded')
39
- expect(preference.user(true).username).to eq('reloaded')
40
- end
41
30
  end
42
31
 
43
32
  end
@@ -5,15 +5,15 @@ RSpec.describe User, type: :model do
5
5
  describe '#has_one' do
6
6
  it 'should create the preference record' do
7
7
  user = FactoryGirl.create(:user)
8
- expect(Preference.find_by(:user_id => user.id)).to eq(nil)
9
- expect{
8
+ expect(Preference.find_by(user_id: user.id)).to eq(nil)
9
+ expect do
10
10
  user.preference
11
- }.to change(Preference, :count).by(1)
11
+ end.to change(Preference, :count).by(1)
12
12
  end
13
13
 
14
14
  it 'should get the pre-existing record' do
15
15
  user = FactoryGirl.create(:user)
16
- preference = FactoryGirl.create(:preference, :user_id => user.id)
16
+ preference = FactoryGirl.create(:preference, user_id: user.id)
17
17
  expect(user.preference).to eq(preference)
18
18
  end
19
19
 
@@ -30,33 +30,22 @@ RSpec.describe User, type: :model do
30
30
  expect(preference.language).to eq('fr')
31
31
  expect(preference.notifications).to eq(true)
32
32
  end
33
-
34
- it 'should reload the record from the database' do
35
- user = FactoryGirl.create(:user)
36
- preference = user.preference
37
-
38
- preference_alt = Preference.find_by(:id => preference.id)
39
- preference_alt.update_attribute(:language, 'ca')
40
-
41
- expect(user.preference.language).to_not eq('ca')
42
- expect(user.preference(true).language).to eq('ca')
43
- end
44
33
  end
45
34
 
46
35
  describe 'errors' do
47
36
  it 'should raise an error if the association does not exist' do
48
- expect{
37
+ expect do
49
38
  User.class_eval('auto_create :does_not_exist')
50
- }.to raise_error(AutomaticRecord::Error::MissingAssociation)
39
+ end.to raise_error(AutomaticRecord::Error::MissingAssociation)
51
40
  end
52
41
 
53
42
  it 'should raise an error if the association is not :belongs_to or :has_one' do
54
- expect{
43
+ expect do
55
44
  User.class_eval do
56
45
  has_many :widgets
57
46
  auto_create :widgets
58
47
  end
59
- }.to raise_error(AutomaticRecord::Error::InvalidAssociation)
48
+ end.to raise_error(AutomaticRecord::Error::InvalidAssociation)
60
49
  end
61
50
  end
62
51
 
@@ -1,12 +1,12 @@
1
1
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
- ENV["RAILS_ENV"] ||= 'test'
2
+ ENV['RAILS_ENV'] ||= 'test'
3
3
  require 'spec_helper'
4
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
5
5
  require 'rspec/rails'
6
6
 
7
7
  # Add additional requires below this line. Rails is not loaded until this point!
8
8
  require 'database_cleaner'
9
- require "factory_girl_rails"
9
+ require 'factory_girl_rails'
10
10
  require 'simplecov'
11
11
 
12
12
  SimpleCov.start 'rails'
@@ -38,48 +38,46 @@ RSpec.configure do |config|
38
38
  mocks.verify_partial_doubles = true
39
39
  end
40
40
 
41
- # The settings below are suggested to provide a good initial experience
42
- # with RSpec, but feel free to customize to your heart's content.
43
- =begin
44
- # These two settings work together to allow you to limit a spec run
45
- # to individual examples or groups you care about by tagging them with
46
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
47
- # get run.
48
- config.filter_run :focus
49
- config.run_all_when_everything_filtered = true
50
-
51
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
52
- # For more details, see:
53
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
54
- # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
55
- # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
56
- config.disable_monkey_patching!
57
-
58
- # Many RSpec users commonly either run the entire suite or an individual
59
- # file, and it's useful to allow more verbose output when running an
60
- # individual spec file.
61
- if config.files_to_run.one?
62
- # Use the documentation formatter for detailed output,
63
- # unless a formatter has already been configured
64
- # (e.g. via a command-line flag).
65
- config.default_formatter = 'doc'
66
- end
67
-
68
- # Print the 10 slowest examples and example groups at the
69
- # end of the spec run, to help surface which specs are running
70
- # particularly slow.
71
- config.profile_examples = 10
72
-
73
- # Run specs in random order to surface order dependencies. If you find an
74
- # order dependency and want to debug it, you can fix the order by providing
75
- # the seed, which is printed after each run.
76
- # --seed 1234
77
- config.order = :random
78
-
79
- # Seed global randomization in this process using the `--seed` CLI option.
80
- # Setting this allows you to use `--seed` to deterministically reproduce
81
- # test failures related to randomization by passing the same `--seed` value
82
- # as the one that triggered the failure.
83
- Kernel.srand config.seed
84
- =end
41
+ # The settings below are suggested to provide a good initial experience
42
+ # with RSpec, but feel free to customize to your heart's content.
43
+ # # These two settings work together to allow you to limit a spec run
44
+ # # to individual examples or groups you care about by tagging them with
45
+ # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
46
+ # # get run.
47
+ # config.filter_run :focus
48
+ # config.run_all_when_everything_filtered = true
49
+ #
50
+ # # Limits the available syntax to the non-monkey patched syntax that is recommended.
51
+ # # For more details, see:
52
+ # # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
53
+ # # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
54
+ # # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
55
+ # config.disable_monkey_patching!
56
+ #
57
+ # # Many RSpec users commonly either run the entire suite or an individual
58
+ # # file, and it's useful to allow more verbose output when running an
59
+ # # individual spec file.
60
+ # if config.files_to_run.one?
61
+ # # Use the documentation formatter for detailed output,
62
+ # # unless a formatter has already been configured
63
+ # # (e.g. via a command-line flag).
64
+ # config.default_formatter = 'doc'
65
+ # end
66
+ #
67
+ # # Print the 10 slowest examples and example groups at the
68
+ # # end of the spec run, to help surface which specs are running
69
+ # # particularly slow.
70
+ # config.profile_examples = 10
71
+ #
72
+ # # Run specs in random order to surface order dependencies. If you find an
73
+ # # order dependency and want to debug it, you can fix the order by providing
74
+ # # the seed, which is printed after each run.
75
+ # # --seed 1234
76
+ # config.order = :random
77
+ #
78
+ # # Seed global randomization in this process using the `--seed` CLI option.
79
+ # # Setting this allows you to use `--seed` to deterministically reproduce
80
+ # # test failures related to randomization by passing the same `--seed` value
81
+ # # as the one that triggered the failure.
82
+ # Kernel.srand config.seed
85
83
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: automatic_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Woods
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-16 00:00:00.000000000 Z
11
+ date: 2017-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.1
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.2.1
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mysql2
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,58 +42,72 @@ dependencies:
42
42
  name: rspec-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 3.1.0
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 3.1.0
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: factory_girl_rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 4.4.1
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 4.4.1
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: database_cleaner
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 1.3.0
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 1.3.0
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: 0.7.1
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - "~>"
108
+ - - ">="
95
109
  - !ruby/object:Gem::Version
96
- version: 0.7.1
110
+ version: '0'
97
111
  description: Automatically create a has_one or belongs_to association the first time
98
112
  it is accessed. Also supports optional default attributes or block usage to customize
99
113
  the record creation.
@@ -178,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
192
  version: '0'
179
193
  requirements: []
180
194
  rubyforge_project:
181
- rubygems_version: 2.4.6
195
+ rubygems_version: 2.5.2
182
196
  signing_key:
183
197
  specification_version: 4
184
198
  summary: Automatically create has_one and belongs_to associations the first time they