Merge pull request #1378 from NARKOZ/validations

validate boolean attributes
This commit is contained in:
Dmitriy Zaporozhets 2012-09-05 04:07:35 -07:00
commit 19a5219746
6 changed files with 12 additions and 4 deletions

View file

@ -323,7 +323,7 @@ GEM
multi_json (~> 1.0) multi_json (~> 1.0)
rubyzip rubyzip
settingslogic (2.0.8) settingslogic (2.0.8)
shoulda-matchers (1.1.0) shoulda-matchers (1.3.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
simplecov (0.6.4) simplecov (0.6.4)
multi_json (~> 1.0) multi_json (~> 1.0)

View file

@ -104,6 +104,8 @@ class Project < ActiveRecord::Base
length: { within: 1..255 } length: { within: 1..255 }
validates :owner, presence: true validates :owner, presence: true
validates :issues_enabled, :wall_enabled, :merge_requests_enabled,
:wiki_enabled, inclusion: { in: [true, false] }
validate :check_limit validate :check_limit
validate :repo_name validate :repo_name

View file

@ -16,7 +16,7 @@ module IssueCommonality
validates :title, validates :title,
presence: true, presence: true,
length: { within: 0..255 } length: { within: 0..255 }
validates :closed, inclusion: { in: [true, false] }
scope :opened, where(closed: false) scope :opened, where(closed: false)
scope :closed, where(closed: true) scope :closed, where(closed: true)

View file

@ -7,6 +7,7 @@ describe Issue do
describe "Validation" do describe "Validation" do
it { should ensure_length_of(:description).is_within(0..2000) } it { should ensure_length_of(:description).is_within(0..2000) }
it { should ensure_inclusion_of(:closed).in_array([true, false]) }
end end
describe 'modules' do describe 'modules' do

View file

@ -9,6 +9,7 @@ describe Milestone do
describe "Validation" do describe "Validation" do
it { should validate_presence_of(:title) } it { should validate_presence_of(:title) }
it { should validate_presence_of(:project_id) } it { should validate_presence_of(:project_id) }
it { should ensure_inclusion_of(:closed).in_array([true, false]) }
end end
let(:milestone) { Factory :milestone } let(:milestone) { Factory :milestone }

View file

@ -37,6 +37,10 @@ describe Project do
# TODO: Formats # TODO: Formats
it { should validate_presence_of(:owner) } 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 it "should not allow new projects beyond user limits" do
project.stub(:owner).and_return(double(can_create_project?: false, projects_limit: 1)) project.stub(:owner).and_return(double(can_create_project?: false, projects_limit: 1))