diff options
author | Rémy Coutable <remy@rymai.me> | 2016-12-07 10:31:21 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-12-07 10:31:21 +0000 |
commit | 5186618bb0220383ae4668b7d023bfbbb52c8948 (patch) | |
tree | 50364478658b52192e16fabec2a7326c827b28e4 /spec/models/snippet_spec.rb | |
parent | 9f8a389ac6c2065e8b4fdf174af18c93ba398d25 (diff) | |
parent | 4e249d5baea99a52915025fc2827d01ab2d77c18 (diff) | |
download | gitlab-ce-5186618bb0220383ae4668b7d023bfbbb52c8948.tar.gz |
Merge branch '25209-improve-length-validators' into 'master'
Use :maximum instead of :within for length validators with a 0..N range
Closes #25209
See merge request !7894
Diffstat (limited to 'spec/models/snippet_spec.rb')
-rw-r--r-- | spec/models/snippet_spec.rb | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb index 79d2843e122..7425a897769 100644 --- a/spec/models/snippet_spec.rb +++ b/spec/models/snippet_spec.rb @@ -23,9 +23,9 @@ describe Snippet, models: true do it { is_expected.to validate_presence_of(:author) } it { is_expected.to validate_presence_of(:title) } - it { is_expected.to validate_length_of(:title).is_within(0..255) } + it { is_expected.to validate_length_of(:title).is_at_most(255) } - it { is_expected.to validate_length_of(:file_name).is_within(0..255) } + it { is_expected.to validate_length_of(:file_name).is_at_most(255) } it { is_expected.to validate_presence_of(:content) } @@ -61,6 +61,26 @@ describe Snippet, models: true do end end + describe '#file_name' do + let(:project) { create(:empty_project) } + + context 'file_name is nil' do + let(:snippet) { create(:snippet, project: project, file_name: nil) } + + it 'returns an empty string' do + expect(snippet.file_name).to eq '' + end + end + + context 'file_name is not nil' do + let(:snippet) { create(:snippet, project: project, file_name: 'foo.txt') } + + it 'returns the file_name' do + expect(snippet.file_name).to eq 'foo.txt' + end + end + end + describe "#content_html_invalidated?" do let(:snippet) { create(:snippet, content: "md", content_html: "html", file_name: "foo.md") } it "invalidates the HTML cache of content when the filename changes" do |