babylonia-rails 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -1
- data/Gemfile +5 -1
- data/babylonia-rails.gemspec +4 -2
- data/lib/babylonia/rails/validator.rb +8 -2
- data/lib/babylonia/rails/version.rb +1 -1
- data/spec/babylonia-rails/persistence_spec.rb +4 -1
- data/spec/babylonia-rails/validator_spec.rb +17 -6
- data/spec/support/database.yml +1 -1
- metadata +6 -5
- data/Gemfile.lock +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23b9f13165bbb20bfdb7df78223d70aeac3a2786
|
4
|
+
data.tar.gz: 9852997ff2602bb4a6fdc3df158849ac70dfcba1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75121a38895577938c5c73c80118aa150621435dd096a28d4b720de9a7ccf0a509ac17f5b48ce0ce8edf3f532b0799eabafe5a3976a5dccd6720f0dbb6bd5812
|
7
|
+
data.tar.gz: 8e1847e0126bd7f30da95912610795719f64e3411b1b69c6f7295bc103ac27f2f5c401becbfe8da221720ead3eb02a09a6c91b631fb182995eed8da2f55c5c7d
|
data/.gitignore
CHANGED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
babylonia-rails
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/babylonia-rails.gemspec
CHANGED
@@ -16,8 +16,10 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
active_record = ENV["ACTIVE_RECORD_VERSION"] || ">= 3.2.0"
|
20
|
+
|
21
|
+
s.add_dependency "babylonia", ">= 0.0.3"
|
22
|
+
s.add_dependency "activerecord", active_record
|
21
23
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
22
24
|
end
|
23
25
|
|
@@ -9,7 +9,10 @@ class LanguagesValidator < ActiveModel::EachValidator
|
|
9
9
|
def validate_languages_present(record, attribute, languages)
|
10
10
|
is = record_attribute_languages(record, attribute)
|
11
11
|
unless is == languages
|
12
|
-
record.errors[attribute] << (options[:message] || "should
|
12
|
+
record.errors[attribute] << (options[:message] || "should be filled in #{(languages - is).map(&:upcase).to_sentence}")
|
13
|
+
(languages - is).each do |lang|
|
14
|
+
record.errors[:"#{attribute}_#{lang}"] << (options[:message] || "should be filled")
|
15
|
+
end
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
@@ -17,7 +20,10 @@ class LanguagesValidator < ActiveModel::EachValidator
|
|
17
20
|
all = record_attribute_languages(record, attribute)
|
18
21
|
in_range = keys_not_matching(record, attribute){|k,v| !range.include?(v.size) }
|
19
22
|
unless all.empty? || all == in_range
|
20
|
-
record.errors[attribute] << (options[:message] || "should be between #{range.first} and #{range.last} characters
|
23
|
+
record.errors[attribute] << (options[:message] || "should be between #{range.first} and #{range.last} characters in #{(all - in_range).map(&:upcase).to_sentence}")
|
24
|
+
(all - in_range).each do |lang|
|
25
|
+
record.errors[:"#{attribute}_#{lang}"] << (options[:message] || "should be between #{range.first} and #{range.last} characters")
|
26
|
+
end
|
21
27
|
end
|
22
28
|
end
|
23
29
|
|
@@ -5,11 +5,14 @@ describe LanguagesValidator do
|
|
5
5
|
class BabylonianField < ActiveRecord::Base
|
6
6
|
|
7
7
|
build_babylonian_tower_on :marshes
|
8
|
-
validates :marshes, languages: { present:
|
8
|
+
validates :marshes, languages: { present: [:de, :en, :it], length: 5..11 }
|
9
9
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "persistence" do
|
13
|
+
before(:each) do
|
14
|
+
I18n.stub available_locales: [:de, :en, :it]
|
15
|
+
end
|
13
16
|
subject { BabylonianField.new(marshes: {en: 'Hello', de: 'Hello', it: 'Hello'})}
|
14
17
|
it "should be possible to store the string value" do
|
15
18
|
subject.save!
|
@@ -5,30 +5,39 @@ describe LanguagesValidator do
|
|
5
5
|
class BabylonianField < ActiveRecord::Base
|
6
6
|
|
7
7
|
build_babylonian_tower_on :marshes
|
8
|
-
validates :marshes, languages: { present:
|
8
|
+
validates :marshes, languages: { present: [:de, :en, :it], length: 5..11 }
|
9
9
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "validations" do
|
13
13
|
subject { BabylonianField.new(marshes: "Hello") }
|
14
14
|
before(:each) do
|
15
|
-
I18n.stub locale: :en
|
15
|
+
I18n.stub locale: :en, available_locales: [:de, :en, :it]
|
16
16
|
end
|
17
17
|
context "presence validations" do
|
18
18
|
context "when invalid" do
|
19
19
|
it "should indicate which languages are not translated" do
|
20
20
|
subject.should_not be_valid
|
21
|
-
subject.errors[:marshes].first.should == "should
|
21
|
+
subject.errors[:marshes].first.should == "should be filled in DE and IT"
|
22
|
+
subject.errors[:marshes_en].should be_empty
|
23
|
+
subject.errors[:marshes_de].first.should == "should be filled"
|
24
|
+
subject.errors[:marshes_it].first.should == "should be filled"
|
22
25
|
end
|
23
26
|
it "should indicate remaining incomplete languages if some are updated" do
|
24
27
|
subject.marshes = {it: 'SOMETHING'}
|
25
28
|
subject.should_not be_valid
|
26
|
-
subject.errors[:marshes].first.should == "should
|
29
|
+
subject.errors[:marshes].first.should == "should be filled in DE"
|
30
|
+
subject.errors[:marshes_en].should be_empty
|
31
|
+
subject.errors[:marshes_it].should be_empty
|
32
|
+
subject.errors[:marshes_de].first.should == "should be filled"
|
27
33
|
end
|
28
34
|
it "should work when attributes are deleted" do
|
29
35
|
subject.marshes = ''
|
30
36
|
subject.should_not be_valid
|
31
|
-
subject.errors[:marshes].first.should == "should
|
37
|
+
subject.errors[:marshes].first.should == "should be filled in DE, EN, and IT"
|
38
|
+
subject.errors[:marshes_en].first.should == "should be filled"
|
39
|
+
subject.errors[:marshes_de].first.should == "should be filled"
|
40
|
+
subject.errors[:marshes_it].first.should == "should be filled"
|
32
41
|
end
|
33
42
|
end
|
34
43
|
context "when valid" do
|
@@ -47,7 +56,9 @@ describe LanguagesValidator do
|
|
47
56
|
context "when invalid" do
|
48
57
|
it "should indicate that the languages that are not in length" do
|
49
58
|
subject.should_not be_valid
|
50
|
-
subject.errors[:marshes].first.should == "should be between 5 and 11 characters
|
59
|
+
subject.errors[:marshes].first.should == "should be between 5 and 11 characters in EN and IT"
|
60
|
+
subject.errors[:marshes_en].first.should == "should be between 5 and 11 characters"
|
61
|
+
subject.errors[:marshes_it].first.should == "should be between 5 and 11 characters"
|
51
62
|
end
|
52
63
|
end
|
53
64
|
context "when valid" do
|
data/spec/support/database.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: babylonia-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Beat Richartz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: babylonia
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.0.
|
19
|
+
version: 0.0.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0.
|
26
|
+
version: 0.0.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,9 +61,10 @@ extra_rdoc_files: []
|
|
61
61
|
files:
|
62
62
|
- .gitignore
|
63
63
|
- .rspec
|
64
|
+
- .ruby-gemset
|
65
|
+
- .ruby-version
|
64
66
|
- .travis.yml
|
65
67
|
- Gemfile
|
66
|
-
- Gemfile.lock
|
67
68
|
- LICENSE
|
68
69
|
- README.rdoc
|
69
70
|
- babylonia-rails.gemspec
|
data/Gemfile.lock
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
babylonia-rails (0.0.1)
|
5
|
-
activerecord (>= 3.2.0)
|
6
|
-
babylonia (>= 0.0.2)
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: http://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activemodel (4.0.1)
|
12
|
-
activesupport (= 4.0.1)
|
13
|
-
builder (~> 3.1.0)
|
14
|
-
activerecord (4.0.1)
|
15
|
-
activemodel (= 4.0.1)
|
16
|
-
activerecord-deprecated_finders (~> 1.0.2)
|
17
|
-
activesupport (= 4.0.1)
|
18
|
-
arel (~> 4.0.0)
|
19
|
-
activerecord-deprecated_finders (1.0.3)
|
20
|
-
activesupport (4.0.1)
|
21
|
-
i18n (~> 0.6, >= 0.6.4)
|
22
|
-
minitest (~> 4.2)
|
23
|
-
multi_json (~> 1.3)
|
24
|
-
thread_safe (~> 0.1)
|
25
|
-
tzinfo (~> 0.3.37)
|
26
|
-
arel (4.0.1)
|
27
|
-
atomic (1.1.14)
|
28
|
-
babylonia (0.0.2)
|
29
|
-
i18n (>= 0.5.0)
|
30
|
-
builder (3.1.4)
|
31
|
-
diff-lcs (1.2.5)
|
32
|
-
i18n (0.6.5)
|
33
|
-
minitest (4.7.5)
|
34
|
-
multi_json (1.8.2)
|
35
|
-
mysql2 (0.3.14)
|
36
|
-
rspec (2.14.1)
|
37
|
-
rspec-core (~> 2.14.0)
|
38
|
-
rspec-expectations (~> 2.14.0)
|
39
|
-
rspec-mocks (~> 2.14.0)
|
40
|
-
rspec-core (2.14.7)
|
41
|
-
rspec-expectations (2.14.4)
|
42
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
43
|
-
rspec-mocks (2.14.4)
|
44
|
-
thread_safe (0.1.3)
|
45
|
-
atomic
|
46
|
-
tzinfo (0.3.38)
|
47
|
-
yard (0.8.7.3)
|
48
|
-
|
49
|
-
PLATFORMS
|
50
|
-
ruby
|
51
|
-
|
52
|
-
DEPENDENCIES
|
53
|
-
babylonia-rails!
|
54
|
-
bundler (>= 1.0.0)
|
55
|
-
mysql2
|
56
|
-
rspec
|
57
|
-
yard (>= 0.7.4)
|