store_complex 0.1.0 → 0.1.1

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: 7dd6dd5f9bad33c4202a6da557a89a36e836d97a
4
- data.tar.gz: 90fcf9af2d65ac867c0aaa2c6de0fedd15644b6f
3
+ metadata.gz: 93b570ae48e04ab47b4157c5bf82544505c976e6
4
+ data.tar.gz: 471276b1fa0d50fb68b4ad33a0b5724a0c18be86
5
5
  SHA512:
6
- metadata.gz: 5250ee091d440fd8b308949b7d40f10e1c3e4cbb862924c5063d7e91238ce45d209c2b213b9f4f2e875e1ed10ffd396da3b97d5bf80b1a4315c9668475c6739b
7
- data.tar.gz: 46ad2e8d03bb125f52883a0fba0ff4dcf66603a5685800415a969138b8fdc860db5c2fe12ed86592ebda1338e6f44304dc6a19443da537040729bd445750557f
6
+ metadata.gz: 8abc36dce1a76414bd3915a1d6fc6dd107b7f3f51957e0ddad9e89799f31f15238f86f72a0945645607a5055cbb59b5f2c658da40e84c8bdb5b1de81d7cfb512
7
+ data.tar.gz: 2720d73e7c08781c5f0ab9fa6afe6d11f3a9f5a7ebb4aff989f99c306293bf01d2dcde4227fb8e5de1d200108d30f3704f3d4653bf8b4f4edefc371ab74ce684
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014 [CONTRIBUTORS.md](https://github.com/moonfly/store_complex/master/CONTRIBUTORS.md)
3
+ Copyright (c) 2014 [CONTRIBUTORS.md](https://github.com/moonfly/store_complex/blob/master/CONTRIBUTORS.md)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -1,5 +1,6 @@
1
1
  require 'store_complex/version'
2
2
  require 'observable_object'
3
+ require 'active_record'
3
4
  require 'json'
4
5
 
5
6
  module StoreComplex
@@ -32,4 +33,4 @@ module StoreComplex
32
33
  end
33
34
  end
34
35
 
35
- ActiveRecord.extend StoreComplex::Accessor
36
+ ActiveRecord::Base.extend StoreComplex::Accessor
@@ -1,3 +1,3 @@
1
1
  module StoreComplex
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,92 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'store_complex'
5
+
6
+ # This file was generated by the `rspec --init` command. Conventionally, all
7
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
9
+ # file to always be loaded, without a need to explicitly require it in any files.
10
+ #
11
+ # Given that it is always loaded, you are encouraged to keep this file as
12
+ # light-weight as possible. Requiring heavyweight dependencies from this file
13
+ # will add to the boot time of your test suite on EVERY test run, even for an
14
+ # individual file that may not need all of that loaded. Instead, consider making
15
+ # a separate helper file that requires the additional dependencies and performs
16
+ # the additional setup, and require it from the spec files that actually need it.
17
+ #
18
+ # The `.rspec` file also contains a few flags that are not defaults but that
19
+ # users commonly want.
20
+ #
21
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
+ RSpec.configure do |config|
23
+ # rspec-expectations config goes here. You can use an alternate
24
+ # assertion/expectation library such as wrong or the stdlib/minitest
25
+ # assertions if you prefer.
26
+ config.expect_with :rspec do |expectations|
27
+ # This option will default to `true` in RSpec 4. It makes the `description`
28
+ # and `failure_message` of custom matchers include text for helper methods
29
+ # defined using `chain`, e.g.:
30
+ # be_bigger_than(2).and_smaller_than(4).description
31
+ # # => "be bigger than 2 and smaller than 4"
32
+ # ...rather than:
33
+ # # => "be bigger than 2"
34
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
+ end
36
+
37
+ # rspec-mocks config goes here. You can use an alternate test double
38
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
39
+ config.mock_with :rspec do |mocks|
40
+ # Prevents you from mocking or stubbing a method that does not exist on
41
+ # a real object. This is generally recommended, and will default to
42
+ # `true` in RSpec 4.
43
+ mocks.verify_partial_doubles = true
44
+ end
45
+
46
+ # The settings below are suggested to provide a good initial experience
47
+ # with RSpec, but feel free to customize to your heart's content.
48
+ # These two settings work together to allow you to limit a spec run
49
+ # to individual examples or groups you care about by tagging them with
50
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
51
+ # get run.
52
+ config.filter_run :focus
53
+ config.run_all_when_everything_filtered = true
54
+
55
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
56
+ # For more details, see:
57
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
58
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
59
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
60
+ config.disable_monkey_patching!
61
+
62
+ # This setting enables warnings. It's recommended, but in some cases may
63
+ # be too noisy due to issues in dependencies.
64
+ config.warnings = true
65
+
66
+ # Many RSpec users commonly either run the entire suite or an individual
67
+ # file, and it's useful to allow more verbose output when running an
68
+ # individual spec file.
69
+ if config.files_to_run.one?
70
+ # Use the documentation formatter for detailed output,
71
+ # unless a formatter has already been configured
72
+ # (e.g. via a command-line flag).
73
+ config.default_formatter = 'doc'
74
+ end
75
+
76
+ # Print the 10 slowest examples and example groups at the
77
+ # end of the spec run, to help surface which specs are running
78
+ # particularly slow.
79
+ config.profile_examples = 10
80
+
81
+ # Run specs in random order to surface order dependencies. If you find an
82
+ # order dependency and want to debug it, you can fix the order by providing
83
+ # the seed, which is printed after each run.
84
+ # --seed 1234
85
+ config.order = :random
86
+
87
+ # Seed global randomization in this process using the `--seed` CLI option.
88
+ # Setting this allows you to use `--seed` to deterministically reproduce
89
+ # test failures related to randomization by passing the same `--seed` value
90
+ # as the one that triggered the failure.
91
+ Kernel.srand config.seed
92
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ class Something < ActiveRecord::Base
4
+ def test_hstore
5
+ @test_hstore ||= {}
6
+ end
7
+ store_complex :test_hstore, :test_attr
8
+ end
9
+
10
+ RSpec.describe 'StoreComplex::obj_to_store' do
11
+ it 'converts nil to nil' do
12
+ expect( StoreComplex::obj_to_store(nil) ).to eq nil
13
+ end
14
+ it 'converts single value to array' do
15
+ expect( JSON.parse( StoreComplex::obj_to_store(1)) ).to eq [1]
16
+ end
17
+ it 'converts array to itself' do
18
+ expect( JSON.parse( StoreComplex::obj_to_store(['a',1]) ) ).to eq ['a',1]
19
+ end
20
+ it 'converts empty array to itself' do
21
+ expect( JSON.parse( StoreComplex::obj_to_store([]) ) ).to eq []
22
+ end
23
+ it 'converts Set to array' do
24
+ expect( JSON.parse( StoreComplex::obj_to_store(Set['a',1]) ) ).to eq ['a',1]
25
+ end
26
+ it 'converts hash to itself' do
27
+ expect( JSON.parse( StoreComplex::obj_to_store( {'a'=>1} ) ) ).to eq( {'a'=>1} )
28
+ end
29
+ it 'converts symbol keys in hash to strings' do
30
+ expect( JSON.parse( StoreComplex::obj_to_store( {a:1} ) ) ).to eq( {'a'=>1} )
31
+ end
32
+ end
33
+
34
+ RSpec.describe 'StoreComplex::store_to_obj' do
35
+ it 'converts nil to empty array' do
36
+ expect( StoreComplex::store_to_obj(nil) ).to eq []
37
+ end
38
+ it 'parses from JSON for non-nil arrays' do
39
+ value = [{'x'=>1},'string',11.67]
40
+ jval = JSON.generate value
41
+ expect( StoreComplex::store_to_obj(jval) ).to eq value
42
+ end
43
+ it 'parses from JSON for non-nil hashes' do
44
+ value = {'x'=>1,'string'=>11.67,'7'=>true}
45
+ jval = JSON.generate value
46
+ expect( StoreComplex::store_to_obj(jval) ).to eq value
47
+ end
48
+ end
49
+
50
+ RSpec.describe StoreComplex do
51
+ it 'has a version (smoke test)' do
52
+ expect(StoreComplex::VERSION).to be_a String
53
+ end
54
+ it 'injects its methods into ActiveRecord' do
55
+ expect(Something.methods).to include *StoreComplex::Accessor.instance_methods
56
+ end
57
+ end
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_development_dependency 'bundler', '>= 1.6'
33
33
  spec.add_development_dependency 'rake'
34
- spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'rspec', '~> 3.1'
35
35
  spec.add_development_dependency 'coveralls'
36
36
  spec.add_development_dependency 'dotenv'
37
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: store_complex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - moonfly (Andrey Pronin)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-12 00:00:00.000000000 Z
11
+ date: 2014-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.0'
75
+ version: '3.1'
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: '3.0'
82
+ version: '3.1'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: coveralls
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -130,6 +130,8 @@ files:
130
130
  - Rakefile
131
131
  - lib/store_complex.rb
132
132
  - lib/store_complex/version.rb
133
+ - spec/spec_helper.rb
134
+ - spec/store_complex_spec.rb
133
135
  - store_complex.gemspec
134
136
  homepage: https://github.com/moonfly/store_complex
135
137
  licenses:
@@ -156,4 +158,6 @@ rubygems_version: 2.2.2
156
158
  signing_key:
157
159
  specification_version: 4
158
160
  summary: Store complex data (arrays, hashes) in hstore attributes
159
- test_files: []
161
+ test_files:
162
+ - spec/spec_helper.rb
163
+ - spec/store_complex_spec.rb