puret 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 06cf90b6509b226d82e70c89ed6edd292e8ae052
4
+ data.tar.gz: 56b7f43e654f3e8a45d930f3762f093578fa717b
5
+ SHA512:
6
+ metadata.gz: 76967eececa86a8b8f5f92fa2fc9ed526223998d9e40984317ccf49db4fdf9f48e620bb60e7989c840385c3e7822f7fc5b19f8b54c087ce54cc2017dad12d101
7
+ data.tar.gz: 686a2682b5ad979933424faf0395331ded2a4ea6de1bfe8e5a017982cd032c13c428b948bed79513aa9d285ec60b42020a561f3cc0a0acea4f63b5f50208ab4b
@@ -8,7 +8,7 @@ module Puret
8
8
  # end
9
9
  def puret_for(model)
10
10
  belongs_to model
11
- validates_presence_of model, :locale
11
+ validates_presence_of :locale
12
12
  validates_uniqueness_of :locale, :scope => "#{model}_id"
13
13
  end
14
14
 
@@ -36,12 +36,16 @@ module Puret
36
36
  # if translation not present in current locale,
37
37
  # use default locale, if present.
38
38
  # Otherwise use first translation
39
- translation = translations.detect { |t| t.locale.to_sym == I18n.locale } ||
40
- translations.detect { |t| t.locale.to_sym == puret_default_locale } ||
39
+ translation = translations.detect { |t| t.locale.to_sym == I18n.locale && t[attribute] } ||
40
+ translations.detect { |t| t.locale.to_sym == puret_default_locale && t[attribute] } ||
41
41
  translations.first
42
42
 
43
43
  translation ? translation[attribute] : nil
44
44
  end
45
+
46
+ define_method "#{attribute}_before_type_cast" do
47
+ self.send(attribute)
48
+ end
45
49
  end
46
50
  end
47
51
 
@@ -52,6 +56,7 @@ module Puret
52
56
  include InstanceMethods
53
57
 
54
58
  has_many :translations, :class_name => "#{self.to_s}Translation", :dependent => :destroy, :order => "created_at DESC"
59
+ validates_associated :translations
55
60
  after_save :update_translations!
56
61
  end
57
62
  end
@@ -118,4 +118,8 @@ class PuretTest < ActiveSupport::TestCase
118
118
  t2 = PostTranslation.new :post => post, :locale => "de"
119
119
  assert_not_nil t2.errors[:locale]
120
120
  end
121
+
122
+ test 'model should provide attribute_before_type_cast' do
123
+ assert_equal Post.first.title, Post.first.title_before_type_cast
124
+ end
121
125
  end
@@ -3,22 +3,14 @@ require 'test/unit'
3
3
  require 'active_support'
4
4
  require "active_record"
5
5
  require 'puret'
6
+ require 'logger'
6
7
 
8
+ ActiveRecord::Base.logger = Logger.new(nil)
7
9
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
8
10
 
9
11
  def setup_db
10
- ActiveRecord::Schema.define(:version => 1) do
11
- create_table :posts do |t|
12
- t.timestamps
13
- end
14
-
15
- create_table :post_translations do |t|
16
- t.references :post
17
- t.string :locale
18
- t.string :title
19
- t.timestamps
20
- end
21
- end
12
+ ActiveRecord::Migration.verbose = false
13
+ load "schema.rb"
22
14
  end
23
15
 
24
16
  def teardown_db
metadata CHANGED
@@ -1,27 +1,23 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: puret
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
5
  platform: ruby
6
- authors:
7
- - "Johannes J\xC3\xB6rg Schmidt"
6
+ authors:
7
+ - Johannes Jörg Schmidt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2010-02-24 00:00:00 +01:00
13
- default_executable:
11
+ date: 2014-08-25 00:00:00.000000000 Z
14
12
  dependencies: []
15
-
16
13
  description: Pure model translations
17
14
  email: schmidt@netzmerk.com
18
15
  executables: []
19
-
20
16
  extensions: []
21
-
22
- extra_rdoc_files:
17
+ extra_rdoc_files:
18
+ - README.rdoc
19
+ files:
23
20
  - README.rdoc
24
- files:
25
21
  - init.rb
26
22
  - lib/generators/puret.rb
27
23
  - lib/generators/puret/attribute/attribute_generator.rb
@@ -32,35 +28,33 @@ files:
32
28
  - lib/puret.rb
33
29
  - lib/puret/active_record_extensions.rb
34
30
  - lib/puret/version.rb
35
- - README.rdoc
36
- has_rdoc: true
31
+ - test/puret_test.rb
32
+ - test/test_helper.rb
37
33
  homepage: http://github.com/jo/puret
38
34
  licenses: []
39
-
35
+ metadata: {}
40
36
  post_install_message:
41
- rdoc_options:
42
- - --charset=UTF-8
43
- require_paths:
37
+ rdoc_options:
38
+ - "--charset=UTF-8"
39
+ require_paths:
44
40
  - lib
45
- required_ruby_version: !ruby/object:Gem::Requirement
46
- requirements:
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
47
43
  - - ">="
48
- - !ruby/object:Gem::Version
49
- version: "0"
50
- version:
51
- required_rubygems_version: !ruby/object:Gem::Requirement
52
- requirements:
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
53
48
  - - ">="
54
- - !ruby/object:Gem::Version
55
- version: "0"
56
- version:
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
57
51
  requirements: []
58
-
59
52
  rubyforge_project:
60
- rubygems_version: 1.3.5
53
+ rubygems_version: 2.2.2
61
54
  signing_key:
62
55
  specification_version: 3
63
56
  summary: Pure model translations
64
- test_files:
57
+ test_files:
65
58
  - test/puret_test.rb
66
59
  - test/test_helper.rb
60
+ has_rdoc: