migrated project_associations to rabl

pull/527/head
Stefan Frank 11 years ago
parent 5e4d55bcb2
commit 799e3dae88
  1. 21
      app/views/api/v2/planning_element_types/_planning_element_type.api.rabl
  2. 23
      app/views/api/v2/project_associations/_project_association.api.rabl
  3. 28
      app/views/api/v2/project_associations/available_projects.api.rabl
  4. 5
      app/views/api/v2/project_associations/index.api.rabl
  5. 10
      app/views/api/v2/project_associations/show.api.rabl
  6. 108
      spec/views/api/v2/project_associations/_project_association_api_rsb_spec.rb
  7. 83
      spec/views/api/v2/project_associations/available_projects_api_json_spec.rb
  8. 65
      spec/views/api/v2/project_associations/index_api_json_spec.rb
  9. 103
      spec/views/api/v2/project_associations/index_api_rsb_spec.rb
  10. 53
      spec/views/api/v2/project_associations/show_api_json_spec.rb

@ -33,23 +33,4 @@ node :color, if: lambda{|type| type.color.present?} do |type|
end
node :created_at, if: lambda{|project| project.created_at.present?} {|project| project.created_at.utc.iso8601}
node :updated_at, if: lambda{|project| project.updated_at.present?} {|project| project.updated_at.utc.iso8601}
#api.planning_element_type do
# api.id(planning_element_type.id)
# api.name(planning_element_type.name)
#
# api.in_aggregation(planning_element_type.in_aggregation)
# api.is_milestone(planning_element_type.is_milestone)
# api.is_default(planning_element_type.is_default)
#
# api.position(planning_element_type.position)
#
# color = planning_element_type.color
# if color.present?
# api.color(:id => color.id, :name => color.name, :hexcode => color.hexcode)
# end
#
# api.created_at(planning_element_type.created_at.utc) if planning_element_type.created_at
# api.updated_at(planning_element_type.updated_at.utc) if planning_element_type.updated_at
#end
node :updated_at, if: lambda{|project| project.updated_at.present?} {|project| project.updated_at.utc.iso8601}

@ -25,22 +25,13 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
object @project_association
attributes :id, :description
api.array :projects, api_meta(:size => @elements.size) do
@elements.each do |element|
project = element[:project]
api.project do
api.id(project.id)
api.name(project.name)
api.identifier(project.identifier)
api.level(element[:level])
child :projects do
attributes :id, :identifier, :name
end
api.created_on(project.created_on.utc.iso8601) if project.created_on
api.updated_on(project.updated_on.utc.iso8601) if project.updated_on
api.disabled(@disabled.include? project)
end
end
end
node :created_at, if: lambda{|project_association| project_association.created_at.present?} {|project_association| project_association.created_at.utc.iso8601}
node :updated_at, if: lambda{|project_association| project_association.updated_at.present?} {|project_association| project_association.updated_at.utc.iso8601}

@ -25,20 +25,18 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
collection @elements => :projects
api.project_association do
api.id(project_association.id)
node do |element|
project = element[:project]
level = element[:level]
api.array(:projects, :size => project_association.projects.size) do
project_association.projects.each do |project|
api.project(:id => project.id,
:identifier => project.identifier,
:name => project.name)
end
end
api.description(project_association.description)
api.created_at(project_association.created_at.utc) if project_association.created_at
api.updated_at(project_association.updated_at.utc) if project_association.updated_at
end
{id: project.id,
name: project.name,
identifier: project.identifier,
level: level,
created_on: project.created_on.utc.iso8601,
updated_on: project.updated_on.utc.iso8601,
disabled: @disabled.include?(project)
}
end

@ -25,6 +25,5 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
render(:partial => '/api/v2/project_associations/project_association.api',
:object => @project_association)
collection @project_associations => :project_associations
extends '/api/v2/project_associations/project_association.api'

@ -25,10 +25,8 @@
#
# See doc/COPYRIGHT.rdoc for more details.
#++
api.array :project_associations, :size => @project_associations.size do
@project_associations.each do |project_association|
render(:partial => '/api/v2/project_associations/project_association.api',
:object => project_association)
end
object @project_association
node :project_association do |project_association|
partial '/api/v2/project_associations/project_association.api', :object => project_association
end

@ -1,108 +0,0 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require File.expand_path('../../../../../spec_helper', __FILE__)
describe 'api/v2/project_associations/_project_association.api' do
before do
view.extend TimelinesHelper
end
# added to pass in locals
def render
params[:format] = 'xml'
super(:partial => 'api/v2/project_associations/project_association.api', :object => project_association)
end
describe 'with an assigned project_association' do
let(:project_a) { FactoryGirl.create(:project, :id => 1234,
:identifier => 'test_project_a',
:name => 'Test Project A') }
let(:project_b) { FactoryGirl.create(:project, :id => 1235,
:identifier => 'test_project_b',
:name => 'Test Project B') }
let(:project_association) { FactoryGirl.build(:project_association,
:id => 1,
:project_a_id => project_a.id,
:project_b_id => project_b.id,
:description => 'Description of this project_association',
:created_at => Time.parse('Thu Jan 06 12:35:00 +0100 2011'),
:updated_at => Time.parse('Fri Jan 07 12:35:00 +0100 2011')) }
it 'renders a project_association node' do
render
response.should have_selector('project_association', :count => 1)
end
describe 'project_association node' do
it 'contains an id element containing the project_association id' do
render
response.should have_selector('project_association id', :text => '1')
end
it 'contains a projects array' do
render
response.should have_selector('project_association projects[size="2"][type=array]', :count => 1)
end
describe 'projects node' do
it 'contains two project nodes - one for each project taking part in the association' do
render
response.should have_selector('project_association projects project', :count => 2)
end
it 'contains one project node for project_a' do
render
response.should have_selector('project_association projects project[id="1234"][identifier=test_project_a][name="Test Project A"]')
end
it 'contains one project node for project_b' do
render
response.should have_selector('project_association projects project[id="1235"][identifier=test_project_b][name="Test Project B"]')
end
end
it 'contains a description element' do
render
response.should have_selector('project_association description', :text => 'Description of this project_association')
end
it 'contains a created_at element containing the project_association created_at in UTC in ISO 8601' do
render
response.should have_selector('project_association created_at', :text => '2011-01-06T11:35:00Z')
end
it 'contains an updated_at element containing the project_association updated_at in UTC in ISO 8601' do
render
response.should have_selector('project_association updated_at', :text => '2011-01-07T11:35:00Z')
end
end
end
end

@ -0,0 +1,83 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require File.expand_path('../../../../../spec_helper', __FILE__)
describe 'api/v2/project_associations/available_projects.api.rabl' do
before do
params[:format] = 'json'
end
describe 'with an assigned project_association' do
let(:project_a) { FactoryGirl.create(:project, :id => 1234,
:identifier => 'test_project_a',
:name => 'Test Project A',
:created_on => Time.parse('Thu Jan 06 12:35:00 +0100 2011'),
:updated_on => Time.parse('Fri Jan 07 12:35:00 +0100 2011')) }
let(:project_b) { FactoryGirl.create(:project, :id => 2345,
:identifier => 'test_project_b',
:name => 'Test Project B',
:created_on => Time.parse('Thu Jan 06 12:35:00 +0100 2011'),
:updated_on => Time.parse('Fri Jan 07 12:35:00 +0100 2011')) }
let(:available_projects) {[{project: project_a, level: 1}]}
let(:disabled_projects) {[{project: project_b, level: 1}]}
before do
assign(:elements, available_projects)
assign(:disabled, disabled_projects)
render
end
subject {response.body}
it 'renders a list of projects available for association' do
puts subject
expected_json = { name: 'Test Project A',
identifier: 'test_project_a',
level: 1,
disabled: false,
created_on: '2011-01-06T11:35:00Z',
updated_on: '2011-01-07T11:35:00Z'
}.to_json
should be_json_eql(expected_json).at_path('projects/0')
end
it ' should check for disabled projects' do
pending
end
end
end

@ -0,0 +1,65 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require File.expand_path('../../../../../spec_helper', __FILE__)
describe 'api/v2/project_associations/index.api.rabl' do
before do
params[:format] = 'json'
end
describe 'with no project_associations available' do
it 'renders an empty project_associations document' do
assign(:project_associations, [])
render
response.should have_json_size(0).at_path('project_associations')
end
end
describe 'with 3 project_associations available' do
let(:project_associations) do
[
FactoryGirl.build(:project_association),
FactoryGirl.build(:project_association),
FactoryGirl.build(:project_association)
]
end
before do
assign(:project_associations, project_associations)
render
end
it 'renders a project_associations document with the size 3 of array' do
response.should have_json_size(3).at_path('project_associations')
end
end
end

@ -1,103 +0,0 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require File.expand_path('../../../../../spec_helper', __FILE__)
describe 'api/v2/project_associations/index.api.rsb' do
before do
view.extend TimelinesHelper
end
before do
params[:format] = 'xml'
end
describe 'with no project_associations available' do
it 'renders an empty project_associations document' do
assign(:project_associations, [])
render
response.should have_selector('project_associations', :count => 1)
response.should have_selector('project_associations[type=array][size="0"]') do
without_tag 'project_association'
end
end
end
describe 'with 3 project_associations available' do
let(:project_associations) do
[
FactoryGirl.build(:project_association),
FactoryGirl.build(:project_association),
FactoryGirl.build(:project_association)
]
end
before do
assign(:project_associations, project_associations)
end
it 'renders a project_associations document with the size 3 of array' do
render
response.should have_selector('project_associations', :count => 1)
response.should have_selector('project_associations[type=array][size="3"]')
end
it 'renders a project_association for each assigned project_association' do
render
response.should have_selector('project_associations project_association', :count => 3)
end
it 'renders the _project_association template for each assigned project_association' do
view.should_receive(:render).exactly(3).times.with(hash_including(:partial => '/api/v2/project_associations/project_association.api')).and_return('')
# just to render the speced template despite the should receive expectations above
view.should_receive(:render).once.with({:template=>"api/v2/project_associations/index", :handlers=>["rsb"], :formats=>["api"]}, {}).and_call_original
render
end
it 'passes the project_associations as local var to the partial' do
view.should_receive(:render).once.with(hash_including(:object => project_associations.first)).and_return('')
view.should_receive(:render).once.with(hash_including(:object => project_associations.second)).and_return('')
view.should_receive(:render).once.with(hash_including(:object => project_associations.third)).and_return('')
# just to render the speced template despite the should receive expectations above
view.should_receive(:render).once.with({:template=>"api/v2/project_associations/index", :handlers=>["rsb"], :formats=>["api"]}, {}).and_call_original
render
end
end
end

@ -28,46 +28,51 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
describe 'api/v2/project_associations/show.api.rsb' do
before do
view.extend TimelinesHelper
end
describe 'api/v2/project_associations/show.api.rabl' do
before do
params[:format] = 'xml'
params[:format] = 'json'
end
describe 'with an assigned project_association' do
let(:project_association) { FactoryGirl.build(:project_association) }
it 'renders a project_association document' do
assign(:project_association, project_association)
render
let(:project_a) { FactoryGirl.create(:project, :id => 1234,
:identifier => 'test_project_a',
:name => 'Test Project A') }
let(:project_b) { FactoryGirl.create(:project, :id => 1235,
:identifier => 'test_project_b',
:name => 'Test Project B') }
response.should have_selector('project_association', :count => 1)
end
let(:project_association) { FactoryGirl.build(:project_association,
:id => 1,
:project_a_id => project_a.id,
:project_b_id => project_b.id,
:description => 'association description #1',
it 'renders the _project_association template once' do
assign(:project_association, project_association)
:created_at => Time.parse('Thu Jan 06 12:35:00 +0100 2011'),
:updated_at => Time.parse('Fri Jan 07 12:35:00 +0100 2011')) }
view.should_receive(:render).once.with(hash_including(:partial => '/api/v2/project_associations/project_association.api')).and_return('')
# just to render the speced template despite the should receive expectations above
view.should_receive(:render).once.with({:template=>"api/v2/project_associations/show", :handlers=>["rsb"], :formats=>["api"]}, {}).and_call_original
before do
assign(:project_association, project_association)
render
end
it 'passes the project_association as local var to the partial' do
assign(:project_association, project_association)
subject {response.body}
view.should_receive(:render).once.with(hash_including(:object => project_association)).and_return('')
it 'renders a project_association document' do
should have_json_path('project_association')
end
# just to render the speced template despite the should receive expectations above
view.should_receive(:render).once.with({:template=>"api/v2/project_associations/show", :handlers=>["rsb"], :formats=>["api"]}, {}).and_call_original
it 'renders the details of the association' do
expected_json = { description: 'association description #1',
projects: [ { name: 'Test Project A',identifier: 'test_project_a'},
{ name: 'Test Project B',identifier: 'test_project_b'}]
}.to_json
render
should be_json_eql(expected_json).at_path('project_association')
end
end
end
Loading…
Cancel
Save