From 2680371785bfac1d0b76e5c4e53aa1074f743f84 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Wed, 5 Sep 2012 03:05:57 -0700 Subject: [PATCH 1/2] bump shoulda-matchers --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7ec37f59..f350b3fc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -323,7 +323,7 @@ GEM multi_json (~> 1.0) rubyzip settingslogic (2.0.8) - shoulda-matchers (1.1.0) + shoulda-matchers (1.3.0) activesupport (>= 3.0.0) simplecov (0.6.4) multi_json (~> 1.0) From 0b559cdece743269a7087c8206ab2cc587ec15f2 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Wed, 5 Sep 2012 03:14:24 -0700 Subject: [PATCH 2/2] add validations for boolean attributes --- app/models/project.rb | 2 ++ app/roles/issue_commonality.rb | 2 +- spec/models/issue_spec.rb | 1 + spec/models/milestone_spec.rb | 1 + spec/models/project_spec.rb | 8 ++++++-- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index fc18ad55..4de836c7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -104,6 +104,8 @@ class Project < ActiveRecord::Base length: { within: 1..255 } validates :owner, presence: true + validates :issues_enabled, :wall_enabled, :merge_requests_enabled, + :wiki_enabled, inclusion: { in: [true, false] } validate :check_limit validate :repo_name diff --git a/app/roles/issue_commonality.rb b/app/roles/issue_commonality.rb index a8fd679d..ac972a70 100644 --- a/app/roles/issue_commonality.rb +++ b/app/roles/issue_commonality.rb @@ -16,7 +16,7 @@ module IssueCommonality validates :title, presence: true, length: { within: 0..255 } - + validates :closed, inclusion: { in: [true, false] } scope :opened, where(closed: false) scope :closed, where(closed: true) diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 69829a4d..ca6307e7 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -7,6 +7,7 @@ describe Issue do describe "Validation" do it { should ensure_length_of(:description).is_within(0..2000) } + it { should ensure_inclusion_of(:closed).in_array([true, false]) } end describe 'modules' do diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index fa15fc8f..f0f0f883 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -9,6 +9,7 @@ describe Milestone do describe "Validation" do it { should validate_presence_of(:title) } it { should validate_presence_of(:project_id) } + it { should ensure_inclusion_of(:closed).in_array([true, false]) } end let(:milestone) { Factory :milestone } diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 5add7ff8..756f69de 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -37,6 +37,10 @@ describe Project do # TODO: Formats it { should validate_presence_of(:owner) } + it { should ensure_inclusion_of(:issues_enabled).in_array([true, false]) } + it { should ensure_inclusion_of(:wall_enabled).in_array([true, false]) } + it { should ensure_inclusion_of(:merge_requests_enabled).in_array([true, false]) } + it { should ensure_inclusion_of(:wiki_enabled).in_array([true, false]) } it "should not allow new projects beyond user limits" do project.stub(:owner).and_return(double(can_create_project?: false, projects_limit: 1)) @@ -239,7 +243,7 @@ describe Project do end end - describe :update_merge_requests do + describe :update_merge_requests do let(:project) { Factory :project } before do @@ -259,7 +263,7 @@ describe Project do @merge_request.closed.should be_true end - it "should update merge request commits with new one if pushed to source branch" do + it "should update merge request commits with new one if pushed to source branch" do @merge_request.last_commit.should == nil project.update_merge_requests("8716fc78f3c65bbf7bcf7b574febd583bc5d2812", "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a", "refs/heads/master", @key.user) @merge_request.reload