Commit 19a52197462b9b508af6e90ed3ae55b653d4949e
Exists in
master
and in
4 other branches
Merge pull request #1378 from NARKOZ/validations
validate boolean attributes
Showing
6 changed files
with
12 additions
and
4 deletions
Show diff stats
Gemfile.lock
| @@ -323,7 +323,7 @@ GEM | @@ -323,7 +323,7 @@ GEM | ||
| 323 | multi_json (~> 1.0) | 323 | multi_json (~> 1.0) |
| 324 | rubyzip | 324 | rubyzip |
| 325 | settingslogic (2.0.8) | 325 | settingslogic (2.0.8) |
| 326 | - shoulda-matchers (1.1.0) | 326 | + shoulda-matchers (1.3.0) |
| 327 | activesupport (>= 3.0.0) | 327 | activesupport (>= 3.0.0) |
| 328 | simplecov (0.6.4) | 328 | simplecov (0.6.4) |
| 329 | multi_json (~> 1.0) | 329 | multi_json (~> 1.0) |
app/models/project.rb
| @@ -104,6 +104,8 @@ class Project < ActiveRecord::Base | @@ -104,6 +104,8 @@ class Project < ActiveRecord::Base | ||
| 104 | length: { within: 1..255 } | 104 | length: { within: 1..255 } |
| 105 | 105 | ||
| 106 | validates :owner, presence: true | 106 | validates :owner, presence: true |
| 107 | + validates :issues_enabled, :wall_enabled, :merge_requests_enabled, | ||
| 108 | + :wiki_enabled, inclusion: { in: [true, false] } | ||
| 107 | validate :check_limit | 109 | validate :check_limit |
| 108 | validate :repo_name | 110 | validate :repo_name |
| 109 | 111 |
app/roles/issue_commonality.rb
| @@ -16,7 +16,7 @@ module IssueCommonality | @@ -16,7 +16,7 @@ module IssueCommonality | ||
| 16 | validates :title, | 16 | validates :title, |
| 17 | presence: true, | 17 | presence: true, |
| 18 | length: { within: 0..255 } | 18 | length: { within: 0..255 } |
| 19 | - | 19 | + validates :closed, inclusion: { in: [true, false] } |
| 20 | 20 | ||
| 21 | scope :opened, where(closed: false) | 21 | scope :opened, where(closed: false) |
| 22 | scope :closed, where(closed: true) | 22 | scope :closed, where(closed: true) |
spec/models/issue_spec.rb
| @@ -7,6 +7,7 @@ describe Issue do | @@ -7,6 +7,7 @@ describe Issue do | ||
| 7 | 7 | ||
| 8 | describe "Validation" do | 8 | describe "Validation" do |
| 9 | it { should ensure_length_of(:description).is_within(0..2000) } | 9 | it { should ensure_length_of(:description).is_within(0..2000) } |
| 10 | + it { should ensure_inclusion_of(:closed).in_array([true, false]) } | ||
| 10 | end | 11 | end |
| 11 | 12 | ||
| 12 | describe 'modules' do | 13 | describe 'modules' do |
spec/models/milestone_spec.rb
| @@ -9,6 +9,7 @@ describe Milestone do | @@ -9,6 +9,7 @@ describe Milestone do | ||
| 9 | describe "Validation" do | 9 | describe "Validation" do |
| 10 | it { should validate_presence_of(:title) } | 10 | it { should validate_presence_of(:title) } |
| 11 | it { should validate_presence_of(:project_id) } | 11 | it { should validate_presence_of(:project_id) } |
| 12 | + it { should ensure_inclusion_of(:closed).in_array([true, false]) } | ||
| 12 | end | 13 | end |
| 13 | 14 | ||
| 14 | let(:milestone) { Factory :milestone } | 15 | let(:milestone) { Factory :milestone } |
spec/models/project_spec.rb
| @@ -37,6 +37,10 @@ describe Project do | @@ -37,6 +37,10 @@ describe Project do | ||
| 37 | # TODO: Formats | 37 | # TODO: Formats |
| 38 | 38 | ||
| 39 | it { should validate_presence_of(:owner) } | 39 | it { should validate_presence_of(:owner) } |
| 40 | + it { should ensure_inclusion_of(:issues_enabled).in_array([true, false]) } | ||
| 41 | + it { should ensure_inclusion_of(:wall_enabled).in_array([true, false]) } | ||
| 42 | + it { should ensure_inclusion_of(:merge_requests_enabled).in_array([true, false]) } | ||
| 43 | + it { should ensure_inclusion_of(:wiki_enabled).in_array([true, false]) } | ||
| 40 | 44 | ||
| 41 | it "should not allow new projects beyond user limits" do | 45 | it "should not allow new projects beyond user limits" do |
| 42 | project.stub(:owner).and_return(double(can_create_project?: false, projects_limit: 1)) | 46 | project.stub(:owner).and_return(double(can_create_project?: false, projects_limit: 1)) |
| @@ -239,7 +243,7 @@ describe Project do | @@ -239,7 +243,7 @@ describe Project do | ||
| 239 | end | 243 | end |
| 240 | end | 244 | end |
| 241 | 245 | ||
| 242 | - describe :update_merge_requests do | 246 | + describe :update_merge_requests do |
| 243 | let(:project) { Factory :project } | 247 | let(:project) { Factory :project } |
| 244 | 248 | ||
| 245 | before do | 249 | before do |
| @@ -259,7 +263,7 @@ describe Project do | @@ -259,7 +263,7 @@ describe Project do | ||
| 259 | @merge_request.closed.should be_true | 263 | @merge_request.closed.should be_true |
| 260 | end | 264 | end |
| 261 | 265 | ||
| 262 | - it "should update merge request commits with new one if pushed to source branch" do | 266 | + it "should update merge request commits with new one if pushed to source branch" do |
| 263 | @merge_request.last_commit.should == nil | 267 | @merge_request.last_commit.should == nil |
| 264 | project.update_merge_requests("8716fc78f3c65bbf7bcf7b574febd583bc5d2812", "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a", "refs/heads/master", @key.user) | 268 | project.update_merge_requests("8716fc78f3c65bbf7bcf7b574febd583bc5d2812", "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a", "refs/heads/master", @key.user) |
| 265 | @merge_request.reload | 269 | @merge_request.reload |