opentie-core 0.0.7 → 0.0.8

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
- ZjA1YTQ1MmMzNTMzNWFjZWYyOTBkYjhmM2IzYzFlNzIwMTZmY2VhZg==
4
+ NDVlZDg2NjQyZTIyOWM0NjVjZjBhY2E0MDJhNWI2ZGYxOTg4ZDNhNA==
5
5
  data.tar.gz: !binary |-
6
- YzYxZTI5NTE5NzA0OWZkODVhYzE4ZmU4OTdjN2VmNDI5NDZlYjNhZQ==
6
+ NjQ3MjdlZmU5MDYzZWViY2JhZWU3NjA2ZTJkMDg4N2Q0ZTVjODYwMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDNhMjE4MDQ1MjMyMDJkMWI1MTJmZTE5NGIxM2I4N2U3NWMzNzk2ZGExYjNi
10
- MTk3MjI1MDNhY2E5YWQ0NzIwNDRkNzVlMjhiOTE2NWEwMzBhZGFkOThjMDU1
11
- NGJiNjhhZjEzZTQzYzIyMTEzZWIyYWJiMmFiMTM1MmQ4YmVmY2M=
9
+ OGRiNzdmYTViZjI1NjliMDBlZmZmZTM4ODVjNGQxZjI3MTg3ZmE1Mzk1YzFm
10
+ MTIxN2RjMDQxNTcyOTg4YzUzMGY2MTE0MDgwNjViY2Y1YWRjYjJmNmUyZjYw
11
+ M2YzNzA4ZmFmMzAyZTY1ZjdiZmNhYTY2YzNhM2VjMWU2ZDNhOWQ=
12
12
  data.tar.gz: !binary |-
13
- ZWZiZTM4N2U4ZmQyNTY0MTUzNDhlYWVhYTZlZDNkMDcwYzcxZjE5YjJkOTli
14
- Zjk3NmJkYjdjNDRjY2QxZmNhMGY2YTg4NWE0MzI5YmZjMDNiMGM2ZDBmOTNi
15
- MTIzZDBkYWI4NTY1M2ZlZTZhYzE4OWJiODA5OWFhOTdhYmNiNzM=
13
+ OTA1YTY2MjYxZDBhMGFlY2Q3ODIyMWZlMGQzMDJhZjM1ZWU5ODAyNjA1ODE3
14
+ ZGEwYWMwZmFkYmEyOGExYWFiYzQwNjY5NzhhYjgxYjdmZTBiMmM0MTQyNWQw
15
+ OWYyNmI0YWI1NDBiYTg1Mzk1MmMzZmVkZmUyMzE5YWQ1NTEzODI=
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.0
data/.travis.yml CHANGED
@@ -10,3 +10,6 @@ deploy:
10
10
  provider: rubygems
11
11
  api_key:
12
12
  secure: en9qumDRaMUYYjixHQX6nJjRKe8J7C3RLn5gvFwZECV1viuPy2Fk7dOTSjcDYZciDqFCi+mnjmwOvqP+KE0gSgKnVvCsh8MfBlhwWLjIVESEUWCNHeDVbnk+e7RySTuiCQvmnXZkJZe2AJvwVX5zOdPu4ouk8hcmkXITGn3fXuI=
13
+ notifications:
14
+ slack:
15
+ secure: ObriTLEO71l8dz5lPyT5O7RblHpSUJ+OElVz1QH4ytQdjL10QlOp1jGbvc9Qsn0ftA3fkTxqXbGR7slFR7isHVF86DR+sg0ghnFpB6X/PDqVjN0Wfb+1ZSHwbaWvK45ePGjTXzGQPdfgGn1g7rpv4X3xe95eCDUUOZBh8GMejCw=
@@ -3,6 +3,9 @@ module Opentie::Core
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
+ include Mongoid::Document
7
+ include Mongoid::Enum
8
+
6
9
  field :auth_token, type: Hash
7
10
  end
8
11
  end
@@ -1,5 +1,10 @@
1
1
  module Opentie::Core
2
2
  module Group
3
-
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ include Mongoid::Document
7
+ include Mongoid::Enum
8
+ end
4
9
  end
5
10
  end
@@ -3,6 +3,9 @@ module Opentie::Core
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
+ include Mongoid::Document
7
+ include Mongoid::Enum
8
+
6
9
  field :created_at, type: Time
7
10
 
8
11
  field :subject, type: String
@@ -1,4 +1,11 @@
1
1
  module Opentie::Core
2
2
  module Persona
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ include Mongoid::Document
7
+ include Mongoid::Enum
8
+ include FormSchema
9
+ end
3
10
  end
4
11
  end
@@ -1,16 +1,19 @@
1
- require_relative 'request'
2
-
3
1
  module Opentie::Core
4
2
  module Project
5
3
  extend ActiveSupport::Concern
6
4
 
5
+ included do
6
+ include FormSchema
7
+ end
8
+
7
9
  module ClassMethods
8
- def request_is(req)
9
- @request = req
10
+ def request_class_name_is(class_name)
11
+ @request_class_name = class_name
12
+ has_many :requests, class_name: class_name, inverse_of: :project
10
13
  end
11
14
 
12
15
  def request_class
13
- @request
16
+ @request_class ||= @request_class_name.constantize
14
17
  end
15
18
  end
16
19
 
@@ -1,45 +1,57 @@
1
- require_relative 'form_schema'
1
+ module Opentie::Core
2
+ module Request
3
+ extend ActiveSupport::Concern
2
4
 
3
- module Opentie
4
- module Core
5
- module Request
6
- extend ActiveSupport::Concern
5
+ included do
6
+ include Mongoid::Document
7
+ include Mongoid::Enum
8
+ include FormSchema
9
+
10
+ @inherited = method(:inherited)
11
+ def self.inherited(subclass)
12
+ @inherited.call subclass
13
+ inherited_hook subclass
14
+ end
15
+
16
+ # list of all requests / applications
17
+ @all_kinds = []
7
18
 
8
- included do
9
- # list of all requests / applications
10
- @all_kinds = []
11
-
12
- field :commited, type: Boolean, default: false
13
- field :created_at, type: Time
14
- field :updated_at, type: Time
15
- end
16
-
17
- module ClassMethods
18
- # helpers for DSL
19
- def subject(t)
20
- @subject = t
21
- end
22
- def application_period(t)
23
- @application_period = t
24
- end
25
- def optional(t)
26
- @optional = t
27
- end
28
- def in_charge_of(t)
29
- @in_charge_of = t
30
- end
31
-
32
- def available? (project)
33
- @application_period.cover? Time.now
34
- end
35
-
36
- def inherited(subclass)
37
- @all_kinds << subclass
38
- end
39
-
40
- def all_request_types
41
- @all_kinds
42
- end
19
+ field :commited, type: Boolean, default: false
20
+ field :created_at, type: Time
21
+ field :updated_at, type: Time
22
+ end
23
+
24
+ module ClassMethods
25
+ def project_class_name_is(class_name)
26
+ belongs_to :project, class_name: class_name, inverse_of: :requests
27
+ end
28
+
29
+ def subject(t)
30
+ @subject = t
31
+ end
32
+
33
+ def application_period(t)
34
+ @application_period = t
35
+ end
36
+
37
+ def optional(t)
38
+ @optional = t
39
+ end
40
+
41
+ def in_charge_of(t)
42
+ @in_charge_of = t
43
+ end
44
+
45
+ def available? (project)
46
+ @application_period.cover? Time.now
47
+ end
48
+
49
+ def inherited_hook(subclass)
50
+ @all_kinds << subclass
51
+ end
52
+
53
+ def all_request_types
54
+ @all_kinds
43
55
  end
44
56
  end
45
57
  end
@@ -1,5 +1,5 @@
1
1
  module Opentie
2
2
  module Core
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
data/lib/opentie/core.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require "active_support"
2
+ require "mongoid"
3
+ require "mongoid/enum"
2
4
 
3
5
  require "opentie/core/version"
6
+ require "opentie/core/form_schema"
4
7
  require "opentie/core/account"
5
8
  require "opentie/core/group"
6
9
  require "opentie/core/project"
data/opentie-core.gemspec CHANGED
@@ -30,4 +30,9 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "guard-rspec"
31
31
  spec.add_development_dependency "factory_girl"
32
32
  spec.add_development_dependency "database_cleaner"
33
+
34
+ spec.add_development_dependency "pry"
35
+ spec.add_development_dependency "pry-byebug"
36
+ spec.add_development_dependency "pry-doc"
37
+ spec.add_development_dependency "better_errors"
33
38
  end
@@ -1,17 +1,8 @@
1
1
  # coding: utf-8
2
2
  require_relative 'spec_helper'
3
- require 'database_cleaner'
4
3
 
5
4
  RSpec.describe Opentie::Core::Project, :type => :model do
6
5
  describe "FakeProject" do
7
- before :each do
8
- DatabaseCleaner.start
9
- end
10
-
11
- after :each do
12
- DatabaseCleaner.clean
13
- end
14
-
15
6
  it "should be able to create" do
16
7
  FakeProject.create!(hoge: :foo)
17
8
  end
data/spec/project_spec.rb CHANGED
@@ -3,21 +3,37 @@ require_relative 'spec_helper'
3
3
  require 'rspec'
4
4
  RSpec.describe Opentie::Core::Project, :type => :model do
5
5
  describe "FakeProject" do
6
- subject(:pr) { FakeProject.new }
6
+ subject(:project) { FakeProject.new }
7
7
 
8
8
  it 'can create instance' do
9
- expect(pr).to be_an_instance_of FakeProject
9
+ expect(project).to be_an_instance_of FakeProject
10
10
  end
11
11
 
12
12
  it 'should return available requests' do
13
13
  allow(Time).to receive(:now).and_return(Time.local(2015, 5, 4, 10))
14
- expect(pr.available_requests).to match_array([TestRequest, AnotherTestRequest])
14
+ expect(project.available_requests).to match_array([TestRequest, AnotherTestRequest])
15
15
 
16
16
  allow(Time).to receive(:now).and_return(Time.local(2015, 4, 4, 10))
17
- expect(pr.available_requests).to match_array([TestRequest])
17
+ expect(project.available_requests).to match_array([TestRequest])
18
18
 
19
19
  allow(Time).to receive(:now).and_return(Time.local(2015, 5, 8, 10))
20
- expect(pr.available_requests).to match_array([AnotherTestRequest])
20
+ expect(project.available_requests).to match_array([AnotherTestRequest])
21
+ end
22
+
23
+ it "should has many requests" do
24
+ project.save
25
+ expect(project.requests.length).to eq 0
26
+
27
+ project.requests << TestRequest.new
28
+ expect(project.requests.length).to eq 1
29
+ project.requests << TestRequest.new
30
+ expect(project.requests.length).to eq 2
31
+
32
+ #expect(project.save).to eq true
33
+
34
+ #binding.pry
35
+ expect(TestRequest.count).to eq 2
36
+ expect(FakeProject.first.requests.length).to eq 2
21
37
  end
22
38
  end
23
39
  end
data/spec/spec_helper.rb CHANGED
@@ -1,20 +1,47 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'bundler/setup'
3
3
  require 'rspec'
4
+ require 'pry'
5
+ require 'database_cleaner'
6
+
4
7
  require 'opentie/core'
5
- require 'mongoid'
6
8
  Mongoid.load!('./spec/mongoid.yml')
7
- require 'mongoid/enum'
8
-
9
- require 'database_cleaner'
10
9
 
11
10
  DatabaseCleaner.strategy = :truncation
12
11
 
12
+ RSpec.configure do |config|
13
+ config.before :each do
14
+ DatabaseCleaner.start
15
+ end
16
+
17
+ config.after :each do
18
+ DatabaseCleaner.clean
19
+ end
20
+ end
21
+
13
22
  class FakeGroup
14
- include Mongoid::Document
15
- include Mongoid::Enum
16
23
  include Opentie::Core::Group
17
- include Opentie::Core::FormSchema
24
+ end
25
+
26
+ class FakeProject < FakeGroup
27
+ include Opentie::Core::Project
28
+
29
+ request_class_name_is "FakeRequest"
30
+
31
+ yes_no "is_ok", "よいか",
32
+ yes: "よい",
33
+ no: "わるい"
34
+
35
+ radio "hoge", "ほげフィールド",
36
+ description: "",
37
+ values: {
38
+ foo: "ふー",
39
+ bar: "ばー",
40
+ baz: "ばず"
41
+ }
42
+
43
+ textarea "text", "書け",
44
+ description: "オイ 書け オラ"
18
45
  end
19
46
 
20
47
  class FakeBureau < FakeGroup
@@ -22,12 +49,11 @@ class FakeBureau < FakeGroup
22
49
  end
23
50
 
24
51
  class FakeRequest
25
- include Mongoid::Document
26
- include Mongoid::Enum
27
52
  include Opentie::Core::Request
28
- include Opentie::Core::FormSchema
53
+
54
+ project_class_name_is "FakeProject"
29
55
 
30
- belongs_to :project, class_name: 'FakeProject', inverse_of: :requests
56
+ #belongs_to :project, class_name: "FakeProject", inverse_of: :requests
31
57
  end
32
58
 
33
59
  class TestRequest < FakeRequest
@@ -46,26 +72,3 @@ class AnotherTestRequest < FakeRequest
46
72
  field :another_fake_number, type: Integer
47
73
  field :another_fake_hash, type: Hash
48
74
  end
49
-
50
- class FakeProject < FakeGroup
51
- include Opentie::Core::Project
52
-
53
- request_is FakeRequest
54
-
55
- yes_no "is_ok", "よいか",
56
- yes: "よい",
57
- no: "わるい"
58
-
59
- radio "hoge", "ほげフィールド",
60
- description: "",
61
- values: {
62
- foo: "ふー",
63
- bar: "ばー",
64
- baz: "ばず"
65
- }
66
-
67
- textarea "text", "書け",
68
- description: "オイ 書け オラ"
69
-
70
- has_many :requests, class_name: 'FakeRequest', inverse_of: :project
71
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentie-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - polamjag
@@ -164,6 +164,62 @@ dependencies:
164
164
  - - ! '>='
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: pry
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: pry-byebug
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ! '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: pry-doc
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ! '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ! '>='
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: better_errors
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ! '>='
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ! '>='
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
167
223
  description:
168
224
  email:
169
225
  - s@polamjag.info
@@ -172,6 +228,7 @@ extensions: []
172
228
  extra_rdoc_files: []
173
229
  files:
174
230
  - .gitignore
231
+ - .ruby-version
175
232
  - .travis.yml
176
233
  - Gemfile
177
234
  - Guardfile