-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'redmine' | ||
|
||
Redmine::Plugin.register :chiliproject_ensure_project_hierarchy do | ||
name 'Ensure Project Hierarchy plugin' | ||
author 'Felix Schäfer' | ||
description 'This plugin ensures subproject identifiers are prefixes with their parent project\'s identifier.' | ||
version '0.0.1' | ||
url 'https://github.com/thegcat/chiliproject_ensure_project_hierarchy' | ||
|
||
::Project::IDENTIFIER_SEPARATOR = "-" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
|
||
describe ProjectsController do | ||
let(:project) {mock_model Project} | ||
let(:parent_project) {mock_model Project, :identifier => "something-witty"} | ||
|
||
describe "when I navigate to the new project page after having clicked the 'New subproject' link" do | ||
let(:do_action) {get :new, :parent_id => parent_project} | ||
|
||
before do | ||
# not testing the other stuff | ||
IssueCustomField.stub!(:find) | ||
Tracker.stub!(:all) | ||
|
||
Project.stub!(:new).and_return project | ||
@controller.stub!(:authorize_global).and_return true | ||
end | ||
|
||
describe "then the identifier of the new project" do | ||
it "should default to the parent's identifier with the project identifier separator" do | ||
project.should_receive(:identifier=).with "#{parent_project.identifier}#{::Project::IDENTIFIER_SEPARATOR}" | ||
do_action | ||
end | ||
end | ||
end | ||
|
||
describe "when I try to save a project with a parent project" do | ||
describe "when the project to save is an existing project" do | ||
let(:do_action) {put :create, :project_id => "abc", :project => {:name => "abc", :parent_id => parent_project.id, :identifier => identifier}} | ||
let(:project) {mock_model Project, :name => "abc", :parent_id => parent_project.id, :identifier => identifier} | ||
|
||
before do | ||
project.stub!(:safe_attributes=) | ||
project.stub!(:save).and_return true | ||
project.stub!(:set_allowed_parent!) | ||
@controller.stub!(:authorize).and_return true | ||
end | ||
|
||
describe "and the submitted identifier is correct" do | ||
let(:identifier) {"#{parent_project.identifier}#{::Project::IDENTIFIER_SEPARATOR}"} | ||
|
||
it "then the creation should be successful" do | ||
do_action | ||
response.should be_success | ||
end | ||
end | ||
|
||
describe "and the submitted identifier is incorrect" do | ||
let(:identifier) {""} | ||
let(:errors) {mock ActiveRecord::Errors} | ||
|
||
before do | ||
project.stub!(:errors).and_return errors | ||
end | ||
|
||
it "then an error should be set on the project" do | ||
errors.should_receive(:add).with :identifier, :prefix_invalid, :prefix => "#{parent_project.identifier}#{::Project::IDENTIFIER_SEPARATOR}" | ||
do_action | ||
end | ||
end | ||
end | ||
|
||
describe "when the project to save is a new project" do | ||
# this uses the same validation, no need to test it again | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
RAILS_ENV = "test" unless defined? RAILS_ENV | ||
|
||
# prevent case where we are using rubygems and test-unit 2.x is installed | ||
begin | ||
require 'rubygems' | ||
gem "test-unit", "~> 1.2.3" | ||
rescue LoadError | ||
end | ||
|
||
begin | ||
#require "config/environment" unless defined? RAILS_ROOT | ||
require 'spec/spec_helper' | ||
rescue LoadError => error | ||
puts <<-EOS | ||
You need to install rspec in your ChiliProject project. | ||
Please execute the following code: | ||
gem install rspec-rails | ||
script/generate rspec | ||
EOS | ||
raise error | ||
end | ||
|
||
require 'redmine_factory_girl' |