Skip to content

Commit

Permalink
Only set localized values are now serialized
Browse files Browse the repository at this point in the history
  • Loading branch information
abrisse committed Feb 22, 2017
1 parent b5fd03a commit 3637f65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/spira/base.rb
Expand Up @@ -329,7 +329,7 @@ def read_attribute(name)
def merge_localized_property(name, arg)
values = read_attribute("#{name}_native")
values.delete_if { |s| s.language == I18n.locale }
values << serialize_localized_property(arg, I18n.locale)
values << serialize_localized_property(arg, I18n.locale) if arg
values
end

Expand Down
19 changes: 13 additions & 6 deletions spec/localized_attributes_spec.rb
Expand Up @@ -6,12 +6,10 @@

describe Spira do

before :all do
class ::Concept < Spira::Base
configure :base_uri => "http://example.org/example/"
property :label, :predicate => RDFS.label, :localized => true
property :num_employees, :predicate => RDF::URI.new('http://example.org/example/identifier')
end
class ::Concept < Spira::Base
configure :base_uri => "http://example.org/example/"
property :label, :predicate => RDF::RDFS.label, :localized => true
property :num_employees, :predicate => RDF::URI.new('http://example.org/example/identifier')
end

let(:company) {
Expand Down Expand Up @@ -88,5 +86,14 @@ class ::Concept < Spira::Base
expect(company.label_native.length).to eql 2
end
end

describe "#save" do
it "only serializes the set values" do
I18n.locale = :en
company.label = nil
company.save!
expect(Spira.repository.size).to eq 2
end
end
end
end

0 comments on commit 3637f65

Please sign in to comment.