copycat 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ FactoryGirl.define do
6
6
  factory :copycat_translation do
7
7
  key { Factory.next(:string) }
8
8
  value { Factory.next(:string) }
9
+ locale { "en" }
9
10
  end
10
11
  end
11
12
 
@@ -89,8 +89,6 @@ feature "downloading and uploading yaml files" do
89
89
  end
90
90
 
91
91
  it "gives 400 on bad upload" do
92
- visit "/copycat_translations.yaml"
93
-
94
92
  file = Tempfile.new 'copycat'
95
93
  file.write "<<<%%#$W%s"
96
94
  file.close
@@ -106,3 +104,64 @@ feature "downloading and uploading yaml files" do
106
104
 
107
105
  end
108
106
 
107
+ feature "locales" do
108
+
109
+ it "displays different text based on users' locale" do
110
+ Factory(:copycat_translation, locale: 'en', key: 'site.index.intro', value: 'world')
111
+ Factory(:copycat_translation, locale: 'es', key: 'site.index.intro', value: 'mundo')
112
+
113
+ I18n.locale = :en
114
+ visit root_path
115
+ page.should have_content 'world'
116
+ page.should_not have_content 'mundo'
117
+
118
+ I18n.locale = :es
119
+ visit root_path
120
+ page.should have_content 'mundo'
121
+ page.should_not have_content 'world'
122
+
123
+ I18n.locale = :fa
124
+ visit root_path
125
+ page.should_not have_content 'world'
126
+ page.should_not have_content 'mundo'
127
+
128
+ I18n.locale = :en # reset
129
+ end
130
+
131
+ it "imports yaml containing multiple locales" do
132
+ file = Tempfile.new 'copycat'
133
+ file.write <<-YAML
134
+ en:
135
+ hello: world
136
+ es:
137
+ hello: mundo
138
+ YAML
139
+ file.close
140
+
141
+ page.driver.browser.basic_authorize COPYCAT_USERNAME, COPYCAT_PASSWORD
142
+ visit upload_copycat_translations_path
143
+ attach_file "file", file.path
144
+ click_button "Upload"
145
+ file.unlink
146
+
147
+ assert CopycatTranslation.count == 2
148
+ a = CopycatTranslation.where(locale: 'en').first
149
+ assert a.key == 'hello'
150
+ assert a.value == 'world'
151
+ b = CopycatTranslation.where(locale: 'es').first
152
+ assert b.key == 'hello'
153
+ assert b.value == 'mundo'
154
+ end
155
+
156
+ it "exports yaml containing multiple locales" do
157
+ Factory(:copycat_translation, locale: 'en', key: 'hello', value: 'world')
158
+ Factory(:copycat_translation, locale: 'es', key: 'hello', value: 'mundo')
159
+
160
+ page.driver.browser.basic_authorize COPYCAT_USERNAME, COPYCAT_PASSWORD
161
+ visit "/copycat_translations.yaml"
162
+ yaml = page.text
163
+ assert yaml =~ /en:\s*hello: world/
164
+ assert yaml =~ /es:\s*hello: mundo/
165
+ end
166
+
167
+ end
@@ -31,30 +31,12 @@ describe Copycat do
31
31
  end
32
32
  it "returns copycat_translation if present" do
33
33
  cct = FactoryGirl.create(:copycat_translation)
34
- base.lookup(nil, cct.key).should == cct.value
34
+ base.lookup(cct.locale, cct.key).should == cct.value
35
35
  end
36
36
  it "creates copycat_translation if one is missing" do
37
- CopycatTranslation.find_by_key('foo').should be_nil
38
- base.lookup(nil, 'foo')
39
- CopycatTranslation.find_by_key('foo').should_not be_nil
40
- end
41
- end
42
-
43
- describe "#hash_flatten" do
44
- it "flattens hashes" do
45
- before = {"a" => {"b" => "c", "d" => "e"}, "f" => {"g" => {"h" => "i", "j" => "k"}, "l" => "m"}}
46
- after = Copycat.hash_flatten(before)
47
- assert after == {"a.b" => "c", "a.d" => "e", "f.g.h" => "i", "f.g.j" => "k", "f.l" => "m"}
48
- end
49
- end
50
-
51
- describe "#hash_fatten" do
52
- it "fattens hashes" do
53
- before = {"a" => {"b" => "c", "d" => "e"}, "f" => {"g" => {"h" => "i"}, "l" => "m"}}
54
- keys = "f.g.j".split(".")
55
- value = "k"
56
- after = Copycat.hash_fatten(before, keys, value)
57
- assert after == {"a" => {"b" => "c", "d" => "e"}, "f" => {"g" => {"h" => "i", "j" => "k"}, "l" => "m"}}
37
+ CopycatTranslation.where(locale: 'en', key: 'foo').should be_empty
38
+ base.lookup('en', 'foo')
39
+ CopycatTranslation.where(locale: 'en', key: 'foo').should_not be_empty
58
40
  end
59
41
  end
60
42
 
@@ -3,6 +3,32 @@ require 'spec_helper'
3
3
 
4
4
  describe CopycatTranslation do
5
5
 
6
+ describe "database constraints" do
7
+ it "validates uniqueness of key & locale" do
8
+ CopycatTranslation.new(key: "foo", locale: "en", value: "bar").save
9
+ a = CopycatTranslation.new(key: "foo", locale: "en", value: "bar2")
10
+ expect { a.save }.should raise_error
11
+ b = CopycatTranslation.new(key: "foo", locale: "fa", value: "bar")
12
+ expect { b.save }.should_not raise_error
13
+ end
14
+ end
15
+
16
+ describe "helper methods" do
17
+ it "flattens hashes" do
18
+ before = {"a" => {"b" => "c", "d" => "e"}, "f" => {"g" => {"h" => "i", "j" => "k"}, "l" => "m"}}
19
+ after = CopycatTranslation.hash_flatten(before)
20
+ assert after == {"a.b" => "c", "a.d" => "e", "f.g.h" => "i", "f.g.j" => "k", "f.l" => "m"}
21
+ end
22
+
23
+ it "fattens hashes" do
24
+ hash = {"a" => {"b" => "c", "d" => "e"}, "f" => {"g" => {"h" => "i"}, "l" => "m"}}
25
+ keys = "f.g.j".split(".")
26
+ value = "k"
27
+ CopycatTranslation.hash_fatten!(hash, keys, value)
28
+ assert hash == {"a" => {"b" => "c", "d" => "e"}, "f" => {"g" => {"h" => "i", "j" => "k"}, "l" => "m"}}
29
+ end
30
+ end
31
+
6
32
  it "imports YAML" do
7
33
  Factory(:copycat_translation, :key => "sample_copy", :value => "copyfoo")
8
34
  Factory(:copycat_translation, :key => "sample_copy2", :value => "copybaz")
@@ -27,7 +53,7 @@ describe CopycatTranslation do
27
53
  it "can be consumed by i18N" do
28
54
  I18n.t('site.title').should_not == 'My Blog'
29
55
  CopycatTranslation.destroy_all
30
- CopycatTranslation.create(key: 'site.title', value: 'My Blog')
56
+ CopycatTranslation.create(key: 'site.title', value: 'My Blog', locale: 'en')
31
57
  data = YAML.load(CopycatTranslation.export_yaml)
32
58
  CopycatTranslation.destroy_all
33
59
  data.each { |locale, d| I18n.backend.store_translations(locale, d || {}) } #i18n/backend/base.rb:159
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: copycat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-19 00:00:00.000000000 Z
13
+ date: 2012-03-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &2151799440 !ruby/object:Gem::Requirement
17
+ requirement: &2151799480 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: 3.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2151799440
25
+ version_requirements: *2151799480
26
26
  description: Edit live website copy.
27
27
  email:
28
28
  - info@vermonster.com
@@ -73,7 +73,7 @@ files:
73
73
  - spec/dummy/config/routes.rb
74
74
  - spec/dummy/config.ru
75
75
  - spec/dummy/db/development.sqlite3
76
- - spec/dummy/db/migrate/20120316153248_create_copycat_translations.copycat_engine.rb
76
+ - spec/dummy/db/migrate/20120320143433_create_copycat_translations.copycat_engine.rb
77
77
  - spec/dummy/db/schema.rb
78
78
  - spec/dummy/db/test.sqlite3
79
79
  - spec/dummy/log/development.log
@@ -147,7 +147,7 @@ test_files:
147
147
  - spec/dummy/config/routes.rb
148
148
  - spec/dummy/config.ru
149
149
  - spec/dummy/db/development.sqlite3
150
- - spec/dummy/db/migrate/20120316153248_create_copycat_translations.copycat_engine.rb
150
+ - spec/dummy/db/migrate/20120320143433_create_copycat_translations.copycat_engine.rb
151
151
  - spec/dummy/db/schema.rb
152
152
  - spec/dummy/db/test.sqlite3
153
153
  - spec/dummy/log/development.log