Added controller specs

This commit is contained in:
Phil Hughes 2017-04-26 11:32:21 +01:00
parent 45e5d12122
commit 480fcb5533
4 changed files with 95 additions and 0 deletions

View file

@ -3,6 +3,7 @@ module MilestoneActions
def merge_requests
respond_to do |format|
format.html { redirect_to milestone_path }
format.json do
render json: tabs_json("shared/milestones/_merge_requests_tab", {
merge_requests: @milestone.merge_requests,
@ -14,6 +15,7 @@ module MilestoneActions
def participants
respond_to do |format|
format.html { redirect_to milestone_path }
format.json do
render json: tabs_json("shared/milestones/_participants_tab", {
users: @milestone.participants
@ -24,6 +26,7 @@ module MilestoneActions
def labels
respond_to do |format|
format.html { redirect_to milestone_path }
format.json do
render json: tabs_json("shared/milestones/_labels_tab", {
labels: @milestone.labels
@ -39,4 +42,12 @@ module MilestoneActions
html: view_to_html_string(partial, data)
}
end
def milestone_path
if @project
namespace_project_milestone_path(@project.namespace, @project, @milestone)
else
group_milestone_path(@group, @milestone.safe_title, title: @milestone.title)
end
end
end

View file

@ -6,6 +6,16 @@ describe Groups::MilestonesController do
let(:project2) { create(:empty_project, group: group) }
let(:user) { create(:user) }
let(:title) { '肯定不是中文的问题' }
let(:milestone) do
project_milestone = create(:milestone, project: project)
GroupMilestone.build(
group,
[project],
project_milestone.title
)
end
let(:milestone_path) { group_milestone_path(group, milestone.safe_title, title: milestone.title) }
before do
sign_in(user)
@ -14,6 +24,8 @@ describe Groups::MilestonesController do
controller.instance_variable_set(:@group, group)
end
it_behaves_like 'milestone tabs'
describe "#create" do
it "creates group milestone with Chinese title" do
post :create,

View file

@ -7,6 +7,7 @@ describe Projects::MilestonesController do
let(:issue) { create(:issue, project: project, milestone: milestone) }
let!(:label) { create(:label, project: project, title: 'Issue Label', issues: [issue]) }
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project, milestone: milestone) }
let(:milestone_path) { namespace_project_milestone_path }
before do
sign_in(user)
@ -14,6 +15,8 @@ describe Projects::MilestonesController do
controller.instance_variable_set(:@project, project)
end
it_behaves_like 'milestone tabs'
describe "#show" do
render_views
@ -49,4 +52,6 @@ describe Projects::MilestonesController do
expect(last_note).to eq('removed milestone')
end
end
end

View file

@ -0,0 +1,67 @@
shared_examples 'milestone tabs' do
def go(path, extra_params = {})
params = if milestone.is_a?(GlobalMilestone)
{ group_id: group.id, id: milestone.safe_title, title: milestone.title }
else
{ namespace_id: project.namespace.to_param, project_id: project, id: milestone.iid }
end
get path, params.merge(extra_params)
end
describe '#merge_requests' do
context 'as html' do
before { go(:merge_requests, format: 'html') }
it 'redirects to milestone#show' do
expect(response).to redirect_to(milestone_path)
end
end
context 'as json' do
before { go(:merge_requests, format: 'json') }
it 'renders the merge requests tab template to a string' do
expect(response).to render_template('shared/milestones/_merge_requests_tab')
expect(json_response).to have_key('html')
end
end
end
describe '#participants' do
context 'as html' do
before { go(:participants, format: 'html') }
it 'redirects to milestone#show' do
expect(response).to redirect_to(milestone_path)
end
end
context 'as json' do
before { go(:participants, format: 'json') }
it 'renders the participants tab template to a string' do
expect(response).to render_template('shared/milestones/_participants_tab')
expect(json_response).to have_key('html')
end
end
end
describe '#labels' do
context 'as html' do
before { go(:labels, format: 'html') }
it 'redirects to milestone#show' do
expect(response).to redirect_to(milestone_path)
end
end
context 'as json' do
before { go(:labels, format: 'json') }
it 'renders the labels tab template to a string' do
expect(response).to render_template('shared/milestones/_labels_tab')
expect(json_response).to have_key('html')
end
end
end
end