diff options
author | Phil Hughes <me@iamphill.com> | 2017-04-26 11:32:21 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-04-26 12:23:29 +0100 |
commit | 480fcb5533e59151a6e9ae11baef59ebab64cc6c (patch) | |
tree | 2c5684dc86ad8ba1a4d96c014843e83cc6492e93 | |
parent | 45e5d12122ac04d7558c84e47003fc8c85a9dddd (diff) | |
download | gitlab-ce-480fcb5533e59151a6e9ae11baef59ebab64cc6c.tar.gz |
Added controller specs
-rw-r--r-- | app/controllers/concerns/milestone_actions.rb | 11 | ||||
-rw-r--r-- | spec/controllers/groups/milestones_controller_spec.rb | 12 | ||||
-rw-r--r-- | spec/controllers/projects/milestones_controller_spec.rb | 5 | ||||
-rw-r--r-- | spec/support/milestone_tabs_examples.rb | 67 |
4 files changed, 95 insertions, 0 deletions
diff --git a/app/controllers/concerns/milestone_actions.rb b/app/controllers/concerns/milestone_actions.rb index c28d08201e0..2cc7e15c27d 100644 --- a/app/controllers/concerns/milestone_actions.rb +++ b/app/controllers/concerns/milestone_actions.rb @@ -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 diff --git a/spec/controllers/groups/milestones_controller_spec.rb b/spec/controllers/groups/milestones_controller_spec.rb index 6e4b5f78e33..7cf2996ffd0 100644 --- a/spec/controllers/groups/milestones_controller_spec.rb +++ b/spec/controllers/groups/milestones_controller_spec.rb @@ -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, diff --git a/spec/controllers/projects/milestones_controller_spec.rb b/spec/controllers/projects/milestones_controller_spec.rb index 47e61c3cea8..6f500468f95 100644 --- a/spec/controllers/projects/milestones_controller_spec.rb +++ b/spec/controllers/projects/milestones_controller_spec.rb @@ -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 diff --git a/spec/support/milestone_tabs_examples.rb b/spec/support/milestone_tabs_examples.rb new file mode 100644 index 00000000000..c48ecb1672e --- /dev/null +++ b/spec/support/milestone_tabs_examples.rb @@ -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 |