renders version name depending on context

Versions being in the same project as the project the view is rendered
for get simply the name as their name attribute. Versions being in a
  different project as the project the view is rendered for get the
  project name prepended to the name as their name attribute. The later
  is also true for when no project is provided as the context.
pull/1928/head
Jens Ulferts 10 years ago
parent 01d2569225
commit 9464e09b71
  1. 10
      app/views/api/experimental/versions/index.api.rabl
  2. 42
      spec/views/api/experimental/versions/index_api_json_spec.rb

@ -1,4 +1,10 @@
collection @versions => :versions
attributes :id,
:name
attributes id: :id
node(:name) do |version|
if version.project == @project
version.name
else
version.to_s_with_project
end
end

@ -28,12 +28,16 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
describe 'api/experimental/versions/index.api.rabl', :type => :view do
describe 'api/experimental/versions/index.api.rabl', type: :view do
let(:project_a) { FactoryGirl.build_stubbed(:project) }
let(:project_b) { FactoryGirl.build_stubbed(:project) }
let(:version_1) { FactoryGirl.build_stubbed(:version, project: project_a) }
let(:version_2) { FactoryGirl.build_stubbed(:version, project: project_a) }
before do
params[:format] = 'json'
assign(:versions, versions)
render
end
subject { response.body }
@ -41,19 +45,43 @@ describe 'api/experimental/versions/index.api.rabl', :type => :view do
describe 'with no versions available' do
let(:versions) { [] }
before do
render
end
it { is_expected.to have_json_path('versions') }
it { is_expected.to have_json_size(0).at_path('versions') }
end
describe 'with 2 versions available' do
let(:versions) { [
FactoryGirl.build(:version), FactoryGirl.build(:version)
] }
describe 'with 2 versions of the project' do
let(:versions) { [version_1, version_2] }
let(:version_1_json) { { id: version_1.id, name: version_1.name }.to_json }
let(:version_2_json) { { id: version_2.id, name: version_2.name }.to_json }
before do
assign(:project, project_a)
render
end
it { is_expected.to have_json_path('versions') }
it { is_expected.to have_json_size(2).at_path('versions') }
it { is_expected.to have_json_type(Object).at_path('versions/1') }
it { is_expected.to have_json_path('versions/1/name') }
it { is_expected.to include_json(version_1_json).at_path('versions') }
it { is_expected.to include_json(version_2_json).at_path('versions') }
end
describe 'with a version that is in a different project' do
let(:versions) { [version_1] }
let(:version_1_json) { { id: version_1.id, name: version_1.to_s_with_project }.to_json }
before do
assign(:project, project_b)
render
end
it { is_expected.to have_json_path('versions') }
it { is_expected.to have_json_size(1).at_path('versions') }
it { is_expected.to include_json(version_1_json).at_path('versions') }
end
end

Loading…
Cancel
Save