|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Article do |
| 4 | + describe ".create" do |
| 5 | + it "builds valid arrays" do |
| 6 | + article = Article.create(:languages => ["English", "German"]) |
| 7 | + article.reload |
| 8 | + article.languages_before_type_cast.should == "{English,German}" |
| 9 | + article.languages.should == ["English", "German"] |
| 10 | + end |
| 11 | + |
| 12 | + it "escapes single quotes correctly" do |
| 13 | + article = Article.create(:languages => ["English", "Ger'man"]) |
| 14 | + article.reload |
| 15 | + article.languages_before_type_cast.should == "{English,Ger''man}" |
| 16 | + article.languages.should == ["English", "Ger'man"] |
| 17 | + end |
| 18 | + |
| 19 | + it "escapes double quotes correctly" do |
| 20 | + article = Article.create(:languages => ["English", "Ger\"man"]) |
| 21 | + article.reload |
| 22 | + article.languages_before_type_cast.should == "{English,\"Ger\\\"man\"}" |
| 23 | + article.languages.should == ["English", "Ger\"man"] |
| 24 | + end |
| 25 | + |
| 26 | + it "handles commas correctly" do |
| 27 | + article = Article.create(:languages => ["English", "Ger,man"]) |
| 28 | + article.reload |
| 29 | + article.languages_before_type_cast.should == "{English,\"Ger,man\"}" |
| 30 | + article.languages.should == ["English", "Ger,man"] |
| 31 | + end |
| 32 | + |
| 33 | + it "handles backslashes correctly" do |
| 34 | + article = Article.create(:languages => ["\\","\""]) |
| 35 | + article.reload |
| 36 | + article.languages_before_type_cast.should == '{"\\\\","\\""}' |
| 37 | + article.languages.should == ["\\","\""] |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + describe ".update" do |
| 42 | + before(:each) do |
| 43 | + @article = Article.create |
| 44 | + end |
| 45 | + |
| 46 | + it "builds valid arrays" do |
| 47 | + @article.languages = ["English", "German"] |
| 48 | + @article.save |
| 49 | + @article.reload |
| 50 | + @article.languages_before_type_cast.should == "{English,German}" |
| 51 | + end |
| 52 | + |
| 53 | + it "escapes single quotes correctly" do |
| 54 | + @article.languages = ["English", "Ger'man"] |
| 55 | + @article.save |
| 56 | + @article.reload |
| 57 | + @article.languages_before_type_cast.should == "{English,Ger'man}" |
| 58 | + @article.languages.should == ["English", "Ger'man"] |
| 59 | + end |
| 60 | + |
| 61 | + it "escapes double quotes correctly" do |
| 62 | + @article.languages = ["English", "Ger\"man"] |
| 63 | + @article.save |
| 64 | + @article.reload |
| 65 | + @article.languages_before_type_cast.should == "{English,\"Ger\\\"man\"}" |
| 66 | + @article.languages.should == ["English", "Ger\"man"] |
| 67 | + end |
| 68 | + |
| 69 | + it "handles commas correctly" do |
| 70 | + @article.languages = ["English", "Ger,man"] |
| 71 | + @article.save |
| 72 | + @article.reload |
| 73 | + @article.languages_before_type_cast.should == "{English,\"Ger,man\"}" |
| 74 | + @article.languages.should == ["English", "Ger,man"] |
| 75 | + end |
| 76 | + |
| 77 | + it "handles backslashes correctly" do |
| 78 | + @article.languages = ["\\","\""] |
| 79 | + @article.save |
| 80 | + @article.reload |
| 81 | + @article.languages_before_type_cast.should == '{"\\\\","\\""}' |
| 82 | + @article.languages.should == ["\\","\""] |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | +end |
0 commit comments