summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-08-08 19:05:40 +0800
committerLin Jen-Shin <godfat@godfat.org>2017-08-08 19:10:46 +0800
commitd831e8e1d06c11e9dc9c0c36767b005a3b86a308 (patch)
tree006f43816dd690c6d2aa4e7d9f0ee24c9bf3d9bf
parentb8ba0efed017b79647421d5ac38c539096b319cc (diff)
downloadgitlab-ce-35098-raise-encoding-confidence-threshold.tar.gz
Add a test to show that threshold 40 would corrupt35098-raise-encoding-confidence-threshold
If we set `ENCODING_CONFIDENCE_THRESHOLD` to 40, this test case would not pass. If we raise to 50, this would pass. Note that if in the future rugged didn't return corrupt data, this would be less relevant. But still icu recommend the threshold to be 50, we should just stick with 50.
-rw-r--r--spec/fixtures/encoding/Japanese.md42
-rw-r--r--spec/lib/gitlab/encoding_helper_spec.rb44
-rw-r--r--spec/support/test_env.rb8
3 files changed, 94 insertions, 0 deletions
diff --git a/spec/fixtures/encoding/Japanese.md b/spec/fixtures/encoding/Japanese.md
new file mode 100644
index 00000000000..dd469c9f232
--- /dev/null
+++ b/spec/fixtures/encoding/Japanese.md
@@ -0,0 +1,42 @@
++++
+date = "2017-05-21T13:05:07+09:00"
+title = "レイヤ"
+weight = 10
+
++++
+
+## このチュートリアルで扱う内容
+1. Redactedにおける2D開発でのレイヤの基本的な概要
+2. スクリーン上のスプライトの順序付け方法
+
+### Redactedにおける2D開発でのレイヤの基本的な概要
+2Dにおいてはz軸が存在しないため、シーン内要素の描画順を制御するためには代替となる仕組みが必要です。
+Redactedでは**レイヤ**における**zIndex**属性を制御可能にすることで、この課題を解決しています。
+**デフォルトでは、zIndexは0となりオブジェクトはレイヤに追加された順番に描画されます。**
+
+レイヤにはいくつかの重要な特性があります。
+
+* レイヤにはレイヤ化されたオブジェクトのみを含めることができます。(**3Dモデルは絶対に追加しないでください**)
+* レイヤはレイヤ化されたオブジェクトです。(したがって、レイヤには他のレイヤを含めることができます)
+* レイヤ化されたオブジェクトは、最大で1つのレイヤに属すことができます。
+
+レイヤを直接初期化することはできませんが、その派生クラスは初期化することが可能です。**Scene2D**と**コンテナ**は、**レイヤ**から派生する2つの主なオブジェクトです。すべての初期化(createContainer、instantiate、...)はレイヤ上で行われます。つまり、2Dで初期化されるすべてのオブジェクトは、zIndexプロパティを持つレイヤ化されたオブジェクトです。
+
+**zIndexはグローバルではありません!**
+
+CSSとは異なり、zIndexはすべてのオブジェクトに対してグローバルではありません。zIndexプロパティは親レイヤに対してローカルです。詳細につきましては、コンテナチュートリアルで説明しています。 [TODO: Link]。
+
+### スクリーン上のスプライトの順序付け方法
+これまで学んだことを生かして、画面にスプライトを表示して、zIndexの設定をしてみましょう!
+
+* まず、最初に (A,B,C) スプライトを生成します。
+* スプライトAをシーンに追加します(zIndex = 0、標準色)
+* スプライトBをシーン2に追加すると、**スプライトAの上に**表示されます(zIndex = 0、赤色)
+* 最後にスプライトCをシーンに追加します(青色)が、スプライトのzIndexを-1に設定すると、スプライトはAとBの後側に表示されます。
+
+{{< code "static/tutorials/layers.html" >}}
+
+### ソースコード全体
+```js
+{{< snippet "static/tutorials/layers.html" >}}
+```
diff --git a/spec/lib/gitlab/encoding_helper_spec.rb b/spec/lib/gitlab/encoding_helper_spec.rb
index 1482ef7132d..26138598651 100644
--- a/spec/lib/gitlab/encoding_helper_spec.rb
+++ b/spec/lib/gitlab/encoding_helper_spec.rb
@@ -30,6 +30,50 @@ describe Gitlab::EncodingHelper do
it 'leaves binary string as is' do
expect(ext_class.encode!(binary_string)).to eq(binary_string)
end
+
+ context 'with corrupted diff' do
+ let(:corrupted_diff) do
+ with_empty_bare_repository do |repo|
+ content = File.read(Rails.root.join(
+ 'spec/fixtures/encoding/Japanese.md').to_s)
+ commit_a = commit(repo, 'Japanese.md', content)
+ commit_b = commit(repo, 'Japanese.md',
+ content.sub('[TODO: Link]', '[現在作業中です: Link]'))
+
+ repo.diff(commit_a, commit_b).each_line.map(&:content).join
+ end
+ end
+
+ let(:cleaned_diff) do
+ corrupted_diff.dup.force_encoding('UTF-8')
+ .encode!('UTF-8', invalid: :replace, replace: '')
+ end
+
+ let(:encoded_diff) do
+ described_class.encode!(corrupted_diff.dup)
+ end
+
+ it 'does not corrupt data but remove invalid characters' do
+ expect(encoded_diff).to eq(cleaned_diff)
+ end
+
+ def commit(repo, path, content)
+ oid = repo.write(content, :blob)
+ index = repo.index
+
+ index.read_tree(repo.head.target.tree) unless repo.empty?
+
+ index.add(path: path, oid: oid, mode: 0100644)
+
+ Rugged::Commit.create(
+ repo,
+ tree: index.write_tree(repo),
+ message: "Update #{path}",
+ parents: repo.empty? ? [] : [repo.head.target].compact,
+ update_ref: 'HEAD'
+ )
+ end
+ end
end
describe '#encode_utf8' do
diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb
index e059c9620ab..1e39f80699c 100644
--- a/spec/support/test_env.rb
+++ b/spec/support/test_env.rb
@@ -250,6 +250,14 @@ module TestEnv
"#{forked_repo_path}_bare"
end
+ def with_empty_bare_repository(name = nil)
+ path = Rails.root.join('tmp/tests', name || 'empty-bare-repository').to_s
+
+ yield(Rugged::Repository.init_at(path, :bare))
+ ensure
+ FileUtils.rm_rf(path)
+ end
+
private
def factory_repo_path