cot 0.1.1 → 0.1.2

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: 531b8bbb2c943a86b2d9041c9b084f5dd4c9bc06
4
- data.tar.gz: f0cebfb0d17cffa7a1f69584662644da4fdfce42
3
+ metadata.gz: 97cc9be92f280e8658df89c21a99f4696a051cf2
4
+ data.tar.gz: 072105df4b9c734f20e1834193a37f76fad112e9
5
5
  SHA512:
6
- metadata.gz: f294e13567ac759dff0966a1fc821428d93a749c483de4bc1c0053636e0e13afb03cfd5f3f9c6d789e4e37c2994047fa5f7c8ee201e03b2da26462201cafc590
7
- data.tar.gz: 2af05c7c27c7ccf7cf0cd39390f9e59c396e00511d68b415e85a25ad000565f3fddb00270dd33d92fb2e5d93e18b48fc858c42fdec917efc6ca958048f2d2be9
6
+ metadata.gz: 68a07d3af871d1793999cdafd4cab1ee7c1134ee78d917f85976dade39e77189f4b67d28c75090d0c14abe255f5a714984254426af2ff08dd4241bcc3f5805b9
7
+ data.tar.gz: a568ee0327301c1cfaf2adcb5352ffd89ff51f264f02ad2aa440c2bf8a75d13f5eca3a34625cf8032ed486d1a9955bcda27544bdd803b796df7dd83185d5fb8c
@@ -0,0 +1,8 @@
1
+ LineLength:
2
+ Max: 120
3
+
4
+ Documentation:
5
+ Enabled: false
6
+
7
+ MethodLength:
8
+ Max: 15
@@ -1,44 +1,64 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cot (0.1.0)
4
+ cot (0.1.1)
5
5
  activemodel
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (4.0.0)
11
- activesupport (= 4.0.0)
12
- builder (~> 3.1.0)
13
- activesupport (4.0.0)
14
- i18n (~> 0.6, >= 0.6.4)
15
- minitest (~> 4.2)
16
- multi_json (~> 1.3)
10
+ activemodel (4.1.4)
11
+ activesupport (= 4.1.4)
12
+ builder (~> 3.1)
13
+ activesupport (4.1.4)
14
+ i18n (~> 0.6, >= 0.6.9)
15
+ json (~> 1.7, >= 1.7.7)
16
+ minitest (~> 5.1)
17
17
  thread_safe (~> 0.1)
18
- tzinfo (~> 0.3.37)
19
- atomic (1.1.13)
20
- builder (3.1.4)
21
- diff-lcs (1.2.4)
22
- i18n (0.6.5)
23
- minitest (4.7.5)
24
- multi_json (1.7.9)
25
- rspec (2.14.1)
26
- rspec-core (~> 2.14.0)
27
- rspec-expectations (~> 2.14.0)
28
- rspec-mocks (~> 2.14.0)
29
- rspec-core (2.14.5)
30
- rspec-expectations (2.14.2)
31
- diff-lcs (>= 1.1.3, < 2.0)
32
- rspec-mocks (2.14.3)
18
+ tzinfo (~> 1.1)
19
+ ast (2.0.0)
20
+ builder (3.2.2)
21
+ diff-lcs (1.2.5)
22
+ i18n (0.6.11)
23
+ json (1.8.1)
24
+ minitest (5.4.0)
25
+ parser (2.2.0.pre.3)
26
+ ast (>= 1.1, < 3.0)
27
+ slop (~> 3.4, >= 3.4.5)
28
+ powerpack (0.0.9)
29
+ rainbow (2.0.0)
30
+ rspec (3.0.0)
31
+ rspec-core (~> 3.0.0)
32
+ rspec-expectations (~> 3.0.0)
33
+ rspec-mocks (~> 3.0.0)
34
+ rspec-core (3.0.2)
35
+ rspec-support (~> 3.0.0)
36
+ rspec-expectations (3.0.2)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.0.0)
39
+ rspec-its (1.0.1)
40
+ rspec-core (>= 2.99.0.beta1)
41
+ rspec-expectations (>= 2.99.0.beta1)
42
+ rspec-mocks (3.0.2)
43
+ rspec-support (~> 3.0.0)
44
+ rspec-support (3.0.2)
45
+ rubocop (0.24.1)
46
+ json (>= 1.7.7, < 2)
47
+ parser (>= 2.2.0.pre.3, < 3.0)
48
+ powerpack (~> 0.0.6)
49
+ rainbow (>= 1.99.1, < 3.0)
50
+ ruby-progressbar (~> 1.4)
51
+ ruby-progressbar (1.5.1)
33
52
  shoulda (3.5.0)
34
53
  shoulda-context (~> 1.0, >= 1.0.1)
35
54
  shoulda-matchers (>= 1.4.1, < 3.0)
36
- shoulda-context (1.1.5)
37
- shoulda-matchers (2.3.0)
55
+ shoulda-context (1.2.1)
56
+ shoulda-matchers (2.6.1)
38
57
  activesupport (>= 3.0.0)
39
- thread_safe (0.1.2)
40
- atomic
41
- tzinfo (0.3.37)
58
+ slop (3.5.0)
59
+ thread_safe (0.3.4)
60
+ tzinfo (1.2.1)
61
+ thread_safe (~> 0.1)
42
62
 
43
63
  PLATFORMS
44
64
  ruby
@@ -47,4 +67,6 @@ DEPENDENCIES
47
67
  bundler (>= 1.0.0)
48
68
  cot!
49
69
  rspec
70
+ rspec-its
71
+ rubocop
50
72
  shoulda
data/Rakefile CHANGED
@@ -8,6 +8,13 @@ RSpec::Core::RakeTask.new('spec') do |spec|
8
8
  spec.rspec_opts = '--tag ~broken'
9
9
  end
10
10
 
11
+ require 'rubocop'
12
+ if defined? RuboCop
13
+ desc 'run rubocop'
14
+ task :rubocop do
15
+ puts `rubocop`
16
+ end
17
+ end
11
18
 
12
- task :default => :spec
13
- task :test => :spec
19
+ task default: [:spec, :rubocop]
20
+ task test: :spec
@@ -1,25 +1,26 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "cot/version"
2
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
+ require 'cot/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'cot'
7
7
  s.version = Cot::VERSION
8
8
 
9
- s.authors = ["Joseph Henrich"]
9
+ s.authors = ['Joseph Henrich']
10
10
  s.email = ['crimsonknave@gmail.com']
11
- s.homepage = %q{http://github.com/crimsonknave/cot}
12
- s.summary = %q{Simplifies creating models for rest based resources}
13
- s.description = %q{Simplifies creating models for rest based resources}
11
+ s.homepage = 'http://github.com/crimsonknave/cot'
12
+ s.summary = 'Simplifies creating models for rest based resources'
13
+ s.description = 'Simplifies creating models for rest based resources'
14
14
 
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
- s.require_paths = ["lib"]
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
+ s.require_paths = ['lib']
19
19
 
20
20
  s.add_dependency 'activemodel'
21
- s.add_development_dependency 'shoulda', ">= 0"
22
- s.add_development_dependency 'bundler', ">= 1.0.0"
23
- s.add_development_dependency 'rspec', ">= 0"
21
+ s.add_development_dependency 'shoulda', '>= 0'
22
+ s.add_development_dependency 'bundler', '>= 1.0.0'
23
+ s.add_development_dependency 'rspec', '>= 0'
24
+ s.add_development_dependency 'rspec-its', '>= 0'
25
+ s.add_development_dependency 'rubocop', '>= 0'
24
26
  end
25
-
data/lib/cot.rb CHANGED
@@ -5,7 +5,6 @@ require 'cot/frame'
5
5
  require 'json'
6
6
 
7
7
  module Cot
8
-
9
8
  def version_string
10
9
  "Cot version #{Cot::VERSION}"
11
10
  end
@@ -5,18 +5,19 @@ module Cot
5
5
  end
6
6
  include ActiveModel::Dirty
7
7
 
8
- def initialize(payload={})
8
+ def initialize(payload = {})
9
9
  @data = convert_keys payload
10
10
  end
11
11
 
12
12
  def exists?
13
- #TODO: Have this key off a defined primary key instead of defaulting to id
13
+ # TODO: Have this key off a defined primary key instead of defaulting to id
14
14
  id
15
15
  end
16
16
 
17
17
  def defined_properties
18
18
  self.class.attr_methods
19
19
  end
20
+
20
21
  def properties_mapping
21
22
  self.class.mappings
22
23
  end
@@ -33,7 +34,7 @@ module Cot
33
34
  self.class.inverted_search_mappings ||= search_mappings.invert
34
35
  end
35
36
 
36
- def self.search_property(name, args={})
37
+ def self.search_property(name, args = {})
37
38
  @search_mappings ||= {}
38
39
 
39
40
  key = args[:from] ? args[:from] : name
@@ -43,11 +44,11 @@ module Cot
43
44
  # TODO: Create an enum declaration that will automagically map a symbol to
44
45
  # another value (such as an int) so that the user of the library doesn't need
45
46
  # to know what number scheduled status is (for example)
46
- def self.enum(name, args={})
47
- raise "enum is not yet implemented"
47
+ def self.enum(_name, _args = {})
48
+ fail 'enum is not yet implemented'
48
49
  end
49
50
 
50
- def self.property(name, args={})
51
+ def self.property(name, args = {})
51
52
  @mappings ||= {}
52
53
  @attr_methods ||= []
53
54
  @search_mappings ||= {}
@@ -82,12 +83,13 @@ module Cot
82
83
  def serializable_hash
83
84
  attrs = {}
84
85
  defined_properties.each do |m|
85
- attrs[inverted_properties_mapping.fetch(m,m)] = self[m]
86
+ attrs[inverted_properties_mapping.fetch(m, m)] = self[m]
86
87
  end
87
88
  attrs
88
89
  end
89
90
 
90
91
  private
92
+
91
93
  def convert_key(key)
92
94
  key = key.to_sym
93
95
  properties_mapping.fetch(key, key).to_sym
@@ -96,11 +98,8 @@ module Cot
96
98
  def convert_keys(hash)
97
99
  return {} unless hash
98
100
  {}.tap do |ret|
99
- hash.each_pair do |k,v|
100
- ret[convert_key k] = v
101
- end
101
+ hash.each_pair { |k, v| ret[convert_key k] = v }
102
102
  end
103
103
  end
104
-
105
104
  end
106
105
  end
@@ -12,13 +12,12 @@ RSpec::Matchers.define :set_search_property do |field|
12
12
  self
13
13
  end
14
14
  end
15
+
15
16
  RSpec::Matchers.define :set_property do |field|
16
17
  match do |base|
17
18
  @tests = {}
18
19
  @tests[:attr_methods] = base.attr_methods.include?(field.to_sym)
19
- if @from
20
- @tests[:mappings] = base.mappings[@from.to_sym] == field
21
- end
20
+ @tests[:mappings] = base.mappings[@from.to_sym] == field if @from
22
21
  if @searchable
23
22
  key = @from ? @from : field
24
23
  @tests[:searchable] = base.search_mappings[field] == key
@@ -34,21 +33,21 @@ RSpec::Matchers.define :set_property do |field|
34
33
  @from = from
35
34
  self
36
35
  end
36
+
37
37
  def searchable
38
38
  @searchable = true
39
39
  self
40
40
  end
41
41
 
42
42
  description do
43
- from_string = @from ? "from #{@from}" : ""
44
- search_string = @searchable ? "to be searchable" : ""
45
- "should set property #{field} #{from_string} #{search_string}"
43
+ from_string = @from ? "from #{@from}" : ''
44
+ search_string = @searchable ? 'to be searchable' : ''
45
+ "sets property #{field} #{from_string} #{search_string}"
46
46
  end
47
47
 
48
- failure_message_for_should do
49
- failed = @tests.select{|k,v| !v}.keys
48
+ failure_message do
49
+ failed = @tests.keys.select { |v| !v }
50
50
  "Expected the property #{field} to be set, but the following attributes weren't set correctly #{failed}"
51
51
  end
52
52
 
53
53
  end
54
-
@@ -1,3 +1,3 @@
1
1
  module Cot
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -2,86 +2,88 @@ require 'spec_helper'
2
2
  describe Cot::Frame do
3
3
  before :each do
4
4
  class TestObject < Cot::Frame
5
- property :foo, :from => :bar
5
+ property :foo, from: :bar
6
6
  property :id
7
- search_property :john, :from => :crichton
7
+ search_property :john, from: :crichton
8
8
  end
9
- @foo = TestObject.new(:bar => 'this will be foo', :id => 5)
9
+ @foo = TestObject.new(bar: 'this will be foo', id: 5)
10
10
  end
11
11
  subject { @foo }
12
12
  its(:to_json) { should be_kind_of String }
13
13
  its(:serializable_hash) { should be_kind_of Hash }
14
- its(:serializable_hash) { should have(2).keys }
15
- it 'should have more serialziable tests'
14
+ it 'has two keys' do
15
+ expect(subject.serializable_hash.size).to eq 2
16
+ end
17
+ it 'needs more serialziable tests'
16
18
  its(:id) { should eq 5 }
17
19
  its(:foo) { should eq 'this will be foo' }
18
20
 
19
21
  context 'exists?' do
20
- it 'should be true if id is present' do
21
- @foo.exists?.should be_true
22
+ it 'is true if id is present' do
23
+ expect(@foo.exists?).to be_truthy
22
24
  end
23
- it 'should be false if id is not present' do
24
- foo = TestObject.new(:foo => 5)
25
- foo.exists?.should be_false
25
+ it 'is false if id is not present' do
26
+ foo = TestObject.new(foo: 5)
27
+ expect(foo.exists?).to be_falsey
26
28
  end
27
29
  end
28
30
  context 'defined_properties' do
29
- it 'should include foo' do
30
- @foo.defined_properties.should include :foo
31
+ it 'includes foo' do
32
+ expect(@foo.defined_properties).to include :foo
31
33
  end
32
- it 'should be an array' do
33
- @foo.defined_properties.should be_kind_of Array
34
+ it 'is an array' do
35
+ expect(@foo.defined_properties).to be_kind_of Array
34
36
  end
35
37
  end
36
38
  context 'properties_mapping' do
37
- it 'should have bar => foo' do
38
- @foo.properties_mapping.should have_key :bar
39
- @foo.properties_mapping[:bar].should eq :foo
39
+ it 'has bar => foo' do
40
+ expect(@foo.properties_mapping).to have_key :bar
41
+ expect(@foo.properties_mapping[:bar]).to eq :foo
40
42
  end
41
43
  end
42
44
  context 'inverted_properties_mapping' do
43
- it 'should have foo => bar' do
44
- @foo.inverted_properties_mapping.should have_key :foo
45
- @foo.inverted_properties_mapping[:foo].should eq :bar
45
+ it 'has foo => bar' do
46
+ expect(@foo.inverted_properties_mapping).to have_key :foo
47
+ expect(@foo.inverted_properties_mapping[:foo]).to eq :bar
46
48
  end
47
49
  end
48
50
  context 'search_mappings' do
49
- it 'should have john => crichton' do
50
- @foo.search_mappings.should have_key :john
51
- @foo.search_mappings[:john].should eq :crichton
51
+ it 'has john => crichton' do
52
+ expect(@foo.search_mappings).to have_key :john
53
+ expect(@foo.search_mappings[:john]).to eq :crichton
52
54
  end
53
55
  end
54
56
  context 'inverted_search_mappings' do
55
- it 'should have crichton => john' do
56
- @foo.inverted_search_mappings.should have_key :crichton
57
- @foo.inverted_search_mappings[:crichton].should eq :john
57
+ it 'has crichton => john' do
58
+ expect(@foo.inverted_search_mappings).to have_key :crichton
59
+ expect(@foo.inverted_search_mappings[:crichton]).to eq :john
58
60
  end
59
61
  end
60
62
  context 'search_property' do
61
- it 'should add to search_mappings' do
62
- TestObject.search_mappings.should have_key :john
63
- TestObject.search_mappings[:john].should be :crichton
63
+ it 'adds to search_mappings' do
64
+ expect(TestObject.search_mappings).to have_key :john
65
+ expect(TestObject.search_mappings[:john]).to be :crichton
64
66
  end
65
67
  end
66
68
  context 'property' do
67
- it 'should add to mappings' do
68
- TestObject.mappings.should have_key :bar
69
- TestObject.mappings[:bar].should be :foo
69
+ it 'adds to mappings' do
70
+ expect(TestObject.mappings).to have_key :bar
71
+ expect(TestObject.mappings[:bar]).to be :foo
70
72
  end
71
- it 'should create accessor methods' do
73
+ it 'creates accessor methods' do
72
74
  foo = TestObject.new
73
- foo.should respond_to :foo
74
- foo.should respond_to :foo=
75
+ expect(foo).to respond_to :foo
76
+ expect(foo).to respond_to :foo=
75
77
  end
76
78
 
77
- it 'should add to attr_methods' do
78
- TestObject.attr_methods.should include(:foo)
79
+ it 'adds to attr_methods' do
80
+ expect(TestObject.attr_methods).to include(:foo)
79
81
  end
80
82
 
81
- it 'accessor methods should use []' do
83
+ it 'accessor methods uses []' do
82
84
  foo = TestObject.new
83
- foo.should_receive('[]').once.and_return 'this is foo'
84
- foo.foo.should eq 'this is foo'
85
+ expect(foo).to receive('[]').once.and_return 'this is foo'
86
+ expect(foo.foo).to eq 'this is foo'
85
87
  end
86
88
  end
87
89
  end
@@ -2,8 +2,9 @@ ENV['RAILS_ENV'] ||= 'test'
2
2
 
3
3
  require 'cot'
4
4
  require 'rspec'
5
+ require 'rspec/its'
5
6
 
6
7
  RSpec.configure do |config|
7
- config.color_enabled = true
8
+ config.color = true
8
9
  config.formatter = 'documentation'
9
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Henrich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-03 00:00:00.000000000 Z
11
+ date: 2014-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
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'
69
97
  description: Simplifies creating models for rest based resources
70
98
  email:
71
99
  - crimsonknave@gmail.com
@@ -74,6 +102,7 @@ extensions: []
74
102
  extra_rdoc_files: []
75
103
  files:
76
104
  - .gitignore
105
+ - .rubocop.yml
77
106
  - .ruby-gemset
78
107
  - .ruby-version
79
108
  - Gemfile