Skip to content

Commit

Permalink
Update activity (#36)
Browse files Browse the repository at this point in the history
* Added project_id to Activity.

* Updated tests.
  • Loading branch information
an-ju authored and adnanhemani committed Apr 21, 2019
1 parent 4c764c1 commit ab1b165
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def rescue_steps(message)
def record_activity
activity_param = {
activity_type: "#{params[:controller]}\##{params[:action]}",
project_id: session[:last_project],
username: current_user.nil? ? nil : current_user['username']
}

Expand Down
16 changes: 13 additions & 3 deletions spec/controllers/dashboard_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
end

def valid_session
{}
{last_project: 1}
end

describe 'GET index' do
Expand All @@ -20,14 +20,14 @@ def valid_session

it 'should create an activity' do
Activity.expects(:create)
.with({username: user.username, activity_type: 'dashboard#index'})
.with({username: user.username, activity_type: 'dashboard#index', project_id: 1})
get :index, {}, valid_session
end
end

describe 'GET project' do
before { @client.stubs(:project) }
let(:params) {{ id: 1 }}
let(:params) {{ id: 2 }}

it 'should call find on PivotalTracker::Project' do
@client.expects(:project).with(params[:id])
Expand All @@ -39,6 +39,10 @@ def valid_session
expect(response).to render_template 'dashboard/ajax/project'
end

it 'should change the session' do
expect{ xhr :get, :project, params, valid_session, format: :js }.to change { session[:last_project] }
end

it 'should create an acvitiy' do
Activity.expects(:create)
.with({
Expand Down Expand Up @@ -82,6 +86,7 @@ def valid_session
username: user.username,
activity_type: 'dashboard#vote',
story_id: '123',
project_id: 1,
activity_data: {
story_id: '123',
vote: '1',
Expand Down Expand Up @@ -123,6 +128,7 @@ def valid_session
username: user.username,
activity_type: 'dashboard#reset',
story_id: '123',
project_id: 1,
activity_data: {story_id: '123', user: decoded_user(params['user'])}.to_json
})
xhr :get, :reset, params, valid_session, format: :js
Expand Down Expand Up @@ -152,6 +158,7 @@ def valid_session
username: user.username,
activity_type: 'dashboard#detail',
story_id: '123',
project_id: 1,
activity_data: {
story_id: '123',
toggle: 'dashboard',
Expand Down Expand Up @@ -184,6 +191,7 @@ def valid_session
username: user.username,
activity_type: 'dashboard#reveal',
story_id: '123',
project_id: 1,
activity_data: {story_id: '123'}.to_json
})
xhr :get, :reveal, params, valid_session, format: :js
Expand Down Expand Up @@ -233,6 +241,7 @@ def valid_session
username: user.username,
activity_type: 'dashboard#update',
story_id: '1',
project_id: 1,
activity_data: fake_return.to_json
})
xhr :post, :update, params, valid_session, format: :js
Expand Down Expand Up @@ -262,6 +271,7 @@ def valid_session
username: user.username,
activity_type: 'dashboard#select',
story_id: '123',
project_id: 1,
activity_data: {story_id: '123', username: 'username'}.to_json
})
xhr :post, :select, params, valid_session, format: :js
Expand Down

0 comments on commit ab1b165

Please sign in to comment.