This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/spec/models/attribute_value_spec.rb

63 lines
2.2 KiB
Ruby

#encoding: UTF-8
require 'spec_helper'
describe AttributeValue do
describe "#attribute_value" do
context "Data should be able to input and out put as aspect"
before do
@af = AttributeField.find '5052cf9f2b5c49a742000005'
@user = User.where(email:'chris@rulingcom.com').first
@av = AttributeValue.last
end #end before
[true,false].each do |locale_sat|
LIST[:markups].each do |markup|
@av = nil
it "[#{markup[0]}]Input: should save data at right way when local is set to #{locale_sat}" do
@af.markup = markup[0]
@av = nil
@input_value = assume_result = case markup[0]
when 'text_field','text_area'
(locale_sat ? {"en"=> "lalala","zh_tw"=>"拉拉拉"} : "hahaha")
when 'select','radio_button'
"1"
when 'date'
{"(1i)"=>Date.today.year.to_s,"(2i)"=>Date.today.month.to_s,"(3i)"=>Date.today.day.to_s}
when 'checkbox'
{"1"=>"true", "3"=>"true"}
end #end of case
assume_result = ["1","3"] if markup[0] == 'checkbox'
@af.locale = locale_sat
@af.save
@data_hash = {"attribute_field_id" => @af.id,"value" => @input_value}
@av = @user.attribute_values.build(@data_hash)
@av.save
@av.value.should == assume_result
# @av.destroy
end
it "[#{markup[0]}]Output(just for show): should output data at right way when local is set to #{locale_sat}" do
locale = I18n.locale
assume_result = case markup[0]
when 'text_area'
(locale_sat ? "拉拉拉" : "hahaha")
when 'text_field'
(locale_sat ? "拉拉拉" : "hahaha")
when 'select','radio_button'
(locale_sat ? "男性" : "男性")
when 'date'
Date.today
when 'checkbox'
(locale_sat ? "男性,不公開" : "男性,不公開")
end #end of case
@av.get_value_by_locale(locale).should == assume_result
end
end #end of LIST loop
end
end
end