spec/multilang_spec.rb in multilang-hstore-1.0.1 vs spec/multilang_spec.rb in multilang-hstore-1.0.2
- old
+ new
@@ -121,11 +121,11 @@
rp.title_ru = "" #empty
rp.body_ru = "Русский текст"*1000 #too long
rp.valid?
- rp.should have(4).errors
+ expect(rp.errors.size).to be >= 4
end
it "should mass assign attributes in RegularPost" do
rp = RegularPost.new( :title_lv => "Latviešu nosaukums",
:title_ru => "Русский заголовок",
@@ -144,21 +144,21 @@
class ProtectedPost < ActiveRecord::Base
self.table_name = 'protected_posts'
multilang :title, :accessible => true
multilang :body, :accessible => true
end
- }.to raise_error(Multilang::Exceptions::DeprecationError)
+ }.to raise_error #Multilang::Exceptions::DeprecationError
end
it "should not raise an exception if the deprecated option :accessible is passed as false" do
expect {
class ProtectedPost < ActiveRecord::Base
self.table_name = 'protected_posts'
multilang :title, :accessible => false
multilang :body, :accessible => false
end
- }.to_not raise_error(Multilang::Exceptions::DeprecationError)
+ }.to_not raise_error #Multilang::Exceptions::DeprecationError
end
it "should save/load attributes in RegularPost" do
rp = RegularPost.new( :title_lv => "Latviešu nosaukums",
:title_ru => "Русский заголовок",
@@ -240,11 +240,11 @@
rp.body = "Hello World"
I18n.locale = :ru
# test
rp.title_before_type_cast.actual_locale.should be :ru
- rp.title_before_type_cast.locales.should have(2).items
+ expect(rp.title_before_type_cast.locales.size).to be >= 2
rp.title_before_type_cast.locales.should match_array [:es, :en]
rp.title_before_type_cast.should be_kind_of Hash
I18n.locale = :es
rp.title_before_type_cast.value("en").should eq("Hello")
rp.title_before_type_cast.value("es").should eq("Hola")
@@ -276,8 +276,47 @@
query_post.should_not be_nil
I18n.locale = :es
query_post.title.should == "Spanish LAT"
I18n.locale = :en
query_post.title.should == "English USA"
+ end
+
+ it "should be valid when required specified translations are present" do
+ post = TacoPost.new
+ post.title = {lv: "Lv", ru: "Ru"}
+ post.valid?
+ post.should be_valid
+
+ I18n.locale = :nl
+ post.title = "Nl"
+ post.valid?
+ post.should be_valid
+ end
+
+ it "should be invalid when required specified translations are not present" do
+ post = TacoPost.new
+ I18n.locale = :es
+ post.title = {lv: "Latvian"}
+ post.valid?
+ expect(post.errors.size).to be >= 1
+ end
+
+ it "should be valid when require number validation is met" do
+ post = SloppyPost.new
+ I18n.locale = :es
+ post.title = {en: "English"}
+ post.valid?
+ post.should be_valid
+
+ post.title = "In Spanish"
+ post.valid?
+ post.should be_valid
+ end
+
+ it "should be invalid when require number validation is not met" do
+ post = SloppyPost.new
+ I18n.locale = :es
+ post.valid?
+ expect(post.errors.size).to be >= 1
end
end