babylonia-rails 0.0.1 → 0.0.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: 1738c0ddff03c286598096590afe14d374dd3131
4
- data.tar.gz: e060718b02decf056a932effd4df2ff08af92a16
3
+ metadata.gz: 23b9f13165bbb20bfdb7df78223d70aeac3a2786
4
+ data.tar.gz: 9852997ff2602bb4a6fdc3df158849ac70dfcba1
5
5
  SHA512:
6
- metadata.gz: 81db6ab131ac20297f73280f6c1147768d9a99c0a7368bd877142158e42c1c86d884fc02eee657b063f71cdc5d72263674d156d475ef68cf687759bfe8c9966f
7
- data.tar.gz: 1f87e602d62a067f580890d4dc94a1aaa2ff9229691def7b7ff5969ed8d8efd1a73c83d1501073edaa425b3fab7bab00901d0490b1ac09dca5347102895b3984
6
+ metadata.gz: 75121a38895577938c5c73c80118aa150621435dd096a28d4b720de9a7ccf0a509ac17f5b48ce0ce8edf3f532b0799eabafe5a3976a5dccd6720f0dbb6bd5812
7
+ data.tar.gz: 8e1847e0126bd7f30da95912610795719f64e3411b1b69c6f7295bc103ac27f2f5c401becbfe8da221720ead3eb02a09a6c91b631fb182995eed8da2f55c5c7d
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ Gemfile.lock
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
@@ -16,3 +17,6 @@ tmp
16
17
  .yardoc
17
18
  _yardoc
18
19
  doc/
20
+
21
+ # Gemnasium gem configuration file
22
+ config/gemnasium.yml
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ babylonia-rails
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0
data/.travis.yml CHANGED
@@ -1,6 +1,11 @@
1
+ services: mysql
2
+ before_script:
3
+ - mysql -e "CREATE DATABASE babylonia_test;"
1
4
  language: ruby
5
+ env:
6
+ - "ACTIVE_RECORD_VERSION='~> 3.2'"
7
+ - "ACTIVE_RECORD_VERSION='>= 4.0.0'"
2
8
  rvm:
3
- - 1.9.2
4
9
  - 1.9.3
5
10
  - 2.0.0
6
11
  - rbx-19mode
data/Gemfile CHANGED
@@ -5,7 +5,11 @@ gemspec
5
5
  group :development do
6
6
  gem "yard", ">= 0.7.4"
7
7
  gem "bundler", ">= 1.0.0"
8
- gem "mysql2"
8
+ if ENV['RUBY_VERSION'] =~ /jruby/
9
+ gem 'activerecord-jdbcmysql-adapter'
10
+ else
11
+ gem "mysql2"
12
+ end
9
13
  end
10
14
 
11
15
  group :test do
@@ -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
- s.add_dependency "babylonia", ">= 0.0.2"
20
- s.add_dependency "activerecord", ">= 3.2.0"
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 also be translated in #{(languages - is).map(&:upcase).to_sentence}")
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 for #{(all - in_range).map(&:upcase).to_sentence}")
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
 
@@ -1,5 +1,5 @@
1
1
  module Babylonia
2
2
  module Rails
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
@@ -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: %i(de en it), length: 5..11 }
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: %i(de en it), length: 5..11 }
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 also be translated in DE and IT"
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 also be translated in DE"
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 also be translated in DE, EN, and IT"
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 for EN and IT"
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
@@ -4,7 +4,7 @@ global: &global
4
4
  encoding: utf8
5
5
 
6
6
  base: &base
7
- username: developer
7
+ username: travis
8
8
  password:
9
9
  host: 127.0.0.1
10
10
  application_timezone: :local
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.1
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-19 00:00:00.000000000 Z
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.2
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.2
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)