purgatory 2.8.0 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2M1NWE4MjU0ZDg0OWE0YTcwNzA3ZGMxYzAwM2U0MWE0ZTVlZTQ5NQ==
4
+ NGMwZjI5OWFhYTNjMWZiY2ExOGJlMmI0MDcyOGNkMjYzNjZhOTFjMA==
5
5
  data.tar.gz: !binary |-
6
- OTEwZDI1MDM3YzhhMGFjNmYxM2RjMTk0NzFhOTY0MmZmMzI3ZjE5Yg==
6
+ OWYxZDJmOGM1NTdkZDRmMjcxY2YwZDUzY2Y1MjA2NTc5MmY0Mjc4Mg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjRmYTU3MGZhNzE1ZDZhZjQ0MDBlNWEwOTNmNThlZDU5YTVjYTVlOGUyZmQz
10
- NGQzZTBiMTMyMzVkNDM5ZmM3NGUyMjU2OGJjOGJlNzEwMDVhMDQ2MWIyMmI5
11
- NDc3ZTExY2I1NGU1MmI4ZjBjZThjM2M3M2MxMThhMDIzZDQ2Mzk=
9
+ ZjhkOGIxOTkxMjYzNjk5N2UwZWM3ZmMwMTQwZjA1NmIzNjYxYjZmZjMzZmJh
10
+ ZDI2MTJhMjgyZTcwNzk2ODUxYWE2MjlkYzkwOGEyM2QxMjBkMzU0ZTVhYjE3
11
+ OGQ2NzEyOTllMDhhNzRkZmE3YTU0MzA2MGY5MTE3MjU1NTFkN2U=
12
12
  data.tar.gz: !binary |-
13
- ZTdlZjc1NzlkZmMxYWY2Y2MyNzRhOTlhMTVmNGNhNDA5NTU2ZDIxZjIyOTU1
14
- MmU1Yzc3YzdlYzEzNTc0MTY3NzdlNzhlMjlhY2Q1NGNiNjhmMDVhMGEzNDRi
15
- ZDY1MTVjODRhYWUxMTY4MjFiZWM4YTBlNmQ2MjM3MjY1Njg3ZGY=
13
+ MmFlMWYyZjJkZGZhNTJiOWVkYWNmZTJlYjI5ZjVlMThjYTkxZjU2MTNmOTc0
14
+ M2JjZjZmM2Q1ZDUzZGM0MjFkMWEyNzgzY2E2NTJhYzliM2JmMjczZTgxMDEy
15
+ ZDFiMjZjNmFmMGQwM2JlNTJjNWY3MTZiMGJiYmE4Y2Q4YWQ4MmM=
data/Gemfile CHANGED
@@ -15,4 +15,5 @@ group :test do
15
15
  gem "activerecord", ">= 4"
16
16
  gem "rspec"
17
17
  gem "sqlite3"
18
+ gem "pry"
18
19
  end
data/Gemfile.lock CHANGED
@@ -20,6 +20,7 @@ GEM
20
20
  arel (4.0.1)
21
21
  atomic (1.1.14)
22
22
  builder (3.1.4)
23
+ coderay (1.1.0)
23
24
  diff-lcs (1.2.5)
24
25
  faraday (0.8.8)
25
26
  multipart-post (~> 1.2.0)
@@ -47,6 +48,7 @@ GEM
47
48
  json (1.8.1)
48
49
  jwt (0.1.8)
49
50
  multi_json (>= 1.5)
51
+ method_source (0.8.2)
50
52
  minitest (4.7.5)
51
53
  multi_json (1.8.2)
52
54
  multi_xml (0.5.5)
@@ -59,6 +61,10 @@ GEM
59
61
  multi_json (~> 1.0)
60
62
  multi_xml (~> 0.5)
61
63
  rack (~> 1.2)
64
+ pry (0.9.12.4)
65
+ coderay (~> 1.0)
66
+ method_source (~> 0.8)
67
+ slop (~> 3.4)
62
68
  rack (1.5.2)
63
69
  rake (10.1.0)
64
70
  rdoc (3.12.2)
@@ -71,6 +77,7 @@ GEM
71
77
  rspec-expectations (2.14.4)
72
78
  diff-lcs (>= 1.1.3, < 2.0)
73
79
  rspec-mocks (2.14.4)
80
+ slop (3.4.7)
74
81
  sqlite3 (1.3.8)
75
82
  thread_safe (0.1.3)
76
83
  atomic
@@ -83,6 +90,7 @@ DEPENDENCIES
83
90
  activerecord (>= 4)
84
91
  bundler (~> 1.0)
85
92
  jeweler (~> 1.8.7)
93
+ pry
86
94
  rdoc (~> 3.12)
87
95
  rspec
88
96
  sqlite3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.8.0
1
+ 2.9.0
@@ -4,13 +4,17 @@ require 'purgatory/active_record_descendant_attribute_accessors'
4
4
 
5
5
  module AttributeAccessorFields
6
6
 
7
- mattr_accessor :local_attributes
7
+ def self.set_local_attributes_to_save(klass,attrs)
8
+ klass.instance_variable_set(:@local_attributes_for_purgatory,attrs)
9
+ end
8
10
 
9
11
  def self.determine_attr_accessor_fields(obj)
10
- variables = if @@local_attributes == :all
12
+ local_attributes = obj.class.instance_variable_get(:@local_attributes_for_purgatory)
13
+
14
+ variables = if local_attributes == :all
11
15
  ActiveRecordDescendantAttributeAccessors.attr_accessor_instance_variables(obj)
12
16
  else
13
- Array(@@local_attributes).map { |attribute|
17
+ Array(local_attributes).map { |attribute|
14
18
  attribute.to_s.prepend('@').to_sym
15
19
  }
16
20
  end
@@ -5,7 +5,7 @@ module PurgatoryModule
5
5
 
6
6
  module ClassMethods
7
7
  def use_purgatory(options={})
8
- AttributeAccessorFields.local_attributes = options[:local_attributes]
8
+ AttributeAccessorFields.set_local_attributes_to_save(self,options[:local_attributes])
9
9
  self.has_many :purgatories, as: :soul
10
10
  end
11
11
  end
data/purgatory.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: purgatory 2.8.0 ruby lib
5
+ # stub: purgatory 2.9.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "purgatory"
9
- s.version = "2.8.0"
9
+ s.version = "2.9.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Elan Dubrofsky"]
@@ -320,15 +320,66 @@ describe Purgatory do
320
320
  end
321
321
  end
322
322
 
323
- describe "determine_attr_accessor_fields" do
324
- before do
325
- AttributeAccessorFields.local_attributes = nil
326
- end
327
-
328
- after do
329
- AttributeAccessorFields.local_attributes = nil
323
+ describe "use_purgatory" do
324
+ context "on class that has attr_accessors" do
325
+ context "use_purgatory with no arguments" do
326
+ before do
327
+ @klass = create_subclass_of(Item)
328
+ @klass.instance_eval { use_purgatory }
329
+ end
330
+
331
+ it "should not store attr_accessors" do
332
+ obj = @klass.new name: 'foo', price: 100, dante: "inferno"
333
+ purgatory = obj.purgatory! user1
334
+ purgatory.attr_accessor_fields.should == {}
335
+ end
336
+ end
337
+
338
+ context "use_purgatory with valid arguments" do
339
+ context "use_purgatory with one active record class" do
340
+ before do
341
+ @klass = create_subclass_of(Item)
342
+ @klass.instance_eval { use_purgatory :local_attributes => [:dante] }
343
+ end
344
+
345
+ it "should work" do
346
+ obj = @klass.new name: 'foo', price: 100, dante: "inferno"
347
+ purgatory = obj.purgatory! user1
348
+ purgatory.attr_accessor_fields.should == { :@dante => "inferno" }
349
+ end
350
+ end
351
+
352
+ context "use_purgatory with more than one active record class" do
353
+ before do
354
+ @klass = create_subclass_of(Item)
355
+ @klass.instance_eval { use_purgatory :local_attributes => [:dante] }
356
+
357
+ @klass_2 = create_subclass_of(Item)
358
+ @klass_2.instance_eval { use_purgatory :local_attributes => [:minos]; attr_accessor :minos }
359
+
360
+ @klass_3 = create_subclass_of(Item)
361
+ @klass_3.instance_eval { use_purgatory }
362
+ end
363
+
364
+ it "should work" do
365
+ obj = @klass.new name: 'foo', price: 100, dante: "inferno"
366
+ purgatory = obj.purgatory! user1
367
+ purgatory.attr_accessor_fields.should == { :@dante => "inferno" }
368
+
369
+ obj = @klass_2.new name: 'foo', price: 100, minos: "inferno"
370
+ purgatory = obj.purgatory! user1
371
+ purgatory.attr_accessor_fields.should == { :@minos => "inferno" }
372
+
373
+ obj = @klass_3.new name: 'foo', price: 100
374
+ purgatory = obj.purgatory! user1
375
+ purgatory.attr_accessor_fields.should == {}
376
+ end
377
+ end
378
+ end
330
379
  end
380
+ end
331
381
 
382
+ describe "determine_attr_accessor_fields" do
332
383
  context "obj has no attr_accessors" do
333
384
  before do
334
385
  @obj = Widget.new
@@ -341,10 +392,10 @@ describe Purgatory do
341
392
 
342
393
  context "obj has attr_accessors" do
343
394
  before do
344
- klass = create_subclass_of(Widget)
345
- klass.instance_eval { attr_accessor :dante, :minos, :charon }
395
+ @klass = create_subclass_of(Widget)
396
+ @klass.instance_eval { attr_accessor :dante, :minos, :charon }
346
397
 
347
- @obj = klass.new
398
+ @obj = @klass.new
348
399
 
349
400
  @obj.dante = "inferno"
350
401
  @obj.minos = "inferno"
@@ -360,7 +411,7 @@ describe Purgatory do
360
411
  context "local_attributes is array" do
361
412
  context "array size is 1" do
362
413
  before do
363
- AttributeAccessorFields.local_attributes = [:dante]
414
+ AttributeAccessorFields.set_local_attributes_to_save(@klass,[:dante])
364
415
  end
365
416
 
366
417
  it "should only contain attr_accessors specified in array" do
@@ -369,7 +420,7 @@ describe Purgatory do
369
420
  end
370
421
  context "array size is more than 1" do
371
422
  before do
372
- AttributeAccessorFields.local_attributes = [:dante, :minos]
423
+ AttributeAccessorFields.set_local_attributes_to_save(@klass,[:dante, :minos])
373
424
  end
374
425
 
375
426
  it "should only contain attr_accessors specified in array" do
@@ -381,7 +432,7 @@ describe Purgatory do
381
432
 
382
433
  context "value of local_variables is :all" do
383
434
  before do
384
- AttributeAccessorFields.local_attributes = :all
435
+ AttributeAccessorFields.set_local_attributes_to_save(@klass,:all)
385
436
  end
386
437
 
387
438
  it "should automatically determine attr_accessor values that doesnt include ones belonging to AR::Base and its ancestors, and then store these values" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purgatory
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elan Dubrofsky