social_snippet-registry_core 0.0.5 → 0.0.6

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
- NzY1ZDExODExYjkxZTA3ZjM5YjI2NzBkNGU3NzhmYzM3MjllNGQ2NA==
4
+ YTNhYTYxNTZmOGUxYzVmMjEzZDM3NDk5NDJiMzg4ZTRmNmU0ZjViNQ==
5
5
  data.tar.gz: !binary |-
6
- NzBiMWVjNWYwZTA0OWIwNWNmZTJmNmEyY2QxOTQxNGMwZTlmNjA4Mw==
6
+ ZTAwYTM3M2FkZTUwZTlmNDA2ZWZlMGVjMzQ2M2Y1Y2Q1Yjc0MmFkYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjUyYTE0MDVkY2Q4M2I2ODhhZGFmNzhiYjk4ODQ1Zjc5ZWM1ZjEwOThhODVl
10
- MTk2NWYyNzhkOTExZjE1MWQ3YmExM2UyZjEyYzIyOGI0ZWEzMWMwNzQ3MzY4
11
- MDI5YzAwNGRlYzljMDA1NWE4NjM4YjQ1NjVhNzdkMGQwY2Q4MjY=
9
+ NTlkNGIzNTVlYTUxZGRiZDJlMTE4Zjc0ODg5NGY2ODFlMjU5YWY2ZTE0Y2E0
10
+ Y2ZiODk3YWU5NTI1NWU0Mjc3M2YxZWExNzMyZTEwM2YzYTA0YzcwZmE3NDEy
11
+ MDE5ODJmMGU2ZmZjNGY0ZDZiYTY0NDNiMTk0N2QwNzhjMWE3MjU=
12
12
  data.tar.gz: !binary |-
13
- NzZlYzdmZjRkNDgwZDQ4ZjhhM2RhZGYwNTkxNTQ1MTljMWVhNzQ5NWY0OThm
14
- NzBiZDRiMTcwMzIyYTEwOGQyNTcyNjJmYjRlNDgzNmQ3YTEyOWUxNjRiOTQz
15
- MjJiYjljNjBkOTQ1NjEyOTAyM2JmMGFkNDA5OTY5Y2MzNDVkMjM=
13
+ MmExMWMxYWZmNGZiNGIxZDU0MzRjZDM0NTRmMDA0NjJlZWMxMjVlZGQ2MmFi
14
+ NjUzZjMxMDFmYjc1NjRjZDY5MmVjMTJkNGY4MzEyMjc3OTNiYzExZDBhY2E0
15
+ YTdkOTc2YmQ5NWY5MmIxMjhmMDNjNGU5YjNiZDI3ZTM2YTEyM2E=
data/Rakefile CHANGED
@@ -13,3 +13,10 @@ RSpec::Core::RakeTask.new(:spec) do |t|
13
13
  ]
14
14
  end
15
15
 
16
+ RSpec::Core::RakeTask.new(:test) do |t|
17
+ t.rspec_opts = [
18
+ "--pattern '../test/*_test.rb'",
19
+ "--color",
20
+ ]
21
+ end
22
+
@@ -3,7 +3,9 @@ class SocialSnippet::Registry::WebAPI::Repository
3
3
  include Mongoid::Document
4
4
  include Mongoid::Timestamps # adds created_at and updated_at fields
5
5
 
6
+ #
6
7
  # field <name>, :type => <type>, :default => <value>
8
+ #
7
9
 
8
10
  # Repository's Name (e.g. "my-repo")
9
11
  field :name, :type => String
@@ -17,6 +19,12 @@ class SocialSnippet::Registry::WebAPI::Repository
17
19
  # Repository's dependencies (e.g. ["dep-to-1", "dep-to-2", ...])
18
20
  field :dependencies, :type => Array, :default => lambda { [] }
19
21
 
22
+ # Repository's license (e.g. MIT)
23
+ field :license, :type => String
24
+
25
+ # Target programming languages (e.g. C++, Ruby)
26
+ field :languages, :type => Array, :default => lambda { [] }
27
+
20
28
  # You can define indexes on documents using the index macro:
21
29
  # index :field <, :unique => true>
22
30
  index({name: 1}, {unique: true})
@@ -24,17 +32,62 @@ class SocialSnippet::Registry::WebAPI::Repository
24
32
  # You can create a composite key in mongoid to replace the default id using the key macro:
25
33
  # key :field <, :another_field, :one_more ....>
26
34
 
35
+ #
27
36
  # validations
37
+ #
28
38
  validates_presence_of :name
39
+ validates_length_of :name, :minimum => 1, :maximum => 64
40
+ validates_each :name do |model, key, value|
41
+ model.errors[:name] << "Invalid name" unless self.is_valid_repo_name?(value)
42
+ end
43
+
44
+ validates_length_of :desc, :maximum => 200
45
+
46
+ validates_length_of :url, :maximum => 256
47
+ validates_each :url do |model, key, value|
48
+ model.errors[:url] << "Invalid URL" unless self.is_valid_url?(value)
49
+ end
29
50
  validates_presence_of :url
30
51
 
52
+ validates_each :dependencies do |model, key, value|
53
+ value.each do |dep|
54
+ unless self.is_valid_repo_name?(dep)
55
+ model.errors[:dependencies] << "invalid deps"
56
+ break
57
+ end
58
+ end
59
+ end
60
+
61
+ validates_each :dependencies do |model, key, value|
62
+ model.errors[:dependencies] << "The size of dependencies must be less than 64" if value.length > 64
63
+ end
64
+
65
+ validates_length_of :license, :maximum => 64
66
+
67
+ validates_each :languages do |model, key, value|
68
+ value.each do |lang|
69
+ unless self.is_valid_language?(lang)
70
+ model.errors[:languages] << "invalid language"
71
+ break
72
+ end
73
+ end
74
+ end
75
+
76
+ validates_each :languages do |model, key, value|
77
+ model.errors[:languages] << "The size of languages must be less than 64" if value.length > 64
78
+ end
79
+
80
+ #
31
81
  # methods
82
+ #
32
83
 
33
84
  FIELD_KEYS = [
34
85
  :name,
35
86
  :url,
36
87
  :desc,
37
88
  :dependencies,
89
+ :license,
90
+ :languages,
38
91
  ]
39
92
 
40
93
  def to_object
@@ -56,6 +109,18 @@ class SocialSnippet::Registry::WebAPI::Repository
56
109
 
57
110
  class << self
58
111
 
112
+ def is_valid_url?(url)
113
+ /^(http|https|git)\:\/\// === url
114
+ end
115
+
116
+ def is_valid_language?(language)
117
+ /^[a-zA-Z0-9\.\-\_\+\#]+$/ === language
118
+ end
119
+
120
+ def is_valid_repo_name?(repo_name)
121
+ /^[a-z][a-z0-9\.\-\_]*$/ === repo_name
122
+ end
123
+
59
124
  def all_repos
60
125
  all.map {|repo| repo.to_object }
61
126
  end
@@ -1,5 +1,5 @@
1
1
  module SocialSnippet
2
2
  module RegistryCore
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -0,0 +1,93 @@
1
+ require "spec_helper"
2
+
3
+ describe ::SocialSnippet::Registry::WebAPI::Repository do
4
+
5
+ describe "validations" do
6
+
7
+ let(:repo) { ::SocialSnippet::Registry::WebAPI::Repository.create }
8
+
9
+ describe "valid cases" do
10
+
11
+ after { expect(repo).to be_valid }
12
+ after { expect { repo.save! }.to_not raise_error }
13
+
14
+ example do
15
+ repo.name = "my-repo"
16
+ repo.url = "git://github.com/user/repo"
17
+ end
18
+
19
+ example do
20
+ repo.name = "my-repo-2"
21
+ repo.url = "git://github.com/user/repo"
22
+ end
23
+
24
+ example do
25
+ repo.name = "my-repo.py"
26
+ repo.url = "git://github.com/user/repo"
27
+ end
28
+
29
+ example do
30
+ repo.name = "my-repository"
31
+ repo.url = "git://github.com/user/repo"
32
+ end
33
+
34
+ example do
35
+ repo.name = "new-repo"
36
+ repo.url = "git://github.com/user/repo"
37
+ end
38
+
39
+ example do
40
+ repo.name = "foo"
41
+ repo.url = "git://github.com/user/repo"
42
+ end
43
+
44
+ example do
45
+ repo.name = "foo.cpp"
46
+ repo.url = "git://github.com/user/repo"
47
+ end
48
+
49
+ end # valid cases
50
+
51
+ describe "invalid cases" do
52
+
53
+ after { expect(repo).to_not be_valid }
54
+ after { expect { repo.save! }.to raise_error }
55
+
56
+ example do
57
+ repo.name = "123"
58
+ repo.url = "git://github.com/user/repo"
59
+ end
60
+
61
+ example do
62
+ repo.name = "invalid@example.com"
63
+ repo.url = "git://github.com/user/repo"
64
+ end
65
+
66
+ example do
67
+ repo.name = "foo"
68
+ repo.dependencies = ["foo", "123"]
69
+ repo.url = "git://github.com/user/repo"
70
+ end
71
+
72
+ example do
73
+ repo.name = "foo"
74
+ repo.dependencies = ["foo", "invalid@example.com"]
75
+ repo.url = "git://github.com/user/repo"
76
+ end
77
+
78
+ example do
79
+ repo.name = "foo"
80
+ repo.url = "file:///etc/passwd"
81
+ end
82
+
83
+ example do
84
+ repo.name = "foo"
85
+ repo.url = "file:///etc/passwd"
86
+ end
87
+
88
+ end
89
+
90
+ end # validations
91
+
92
+ end # ::SocialSnippet::Registry::WebAPI::Repository
93
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_snippet-registry_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroyuki Sano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -223,6 +223,7 @@ files:
223
223
  - spec/webapi/controllers/v0/repositories_controller_spec.rb
224
224
  - spec/webapi/helpers/url_helper_spec.rb
225
225
  - spec/webapi/models/repository_spec.rb
226
+ - test/repository_test.rb
226
227
  homepage: https://sspm.herokuapp.com
227
228
  licenses:
228
229
  - MIT
@@ -255,3 +256,4 @@ test_files:
255
256
  - spec/webapi/controllers/v0/repositories_controller_spec.rb
256
257
  - spec/webapi/helpers/url_helper_spec.rb
257
258
  - spec/webapi/models/repository_spec.rb
259
+ - test/repository_test.rb