Fix "request methods will accept only keyword arguments" deprecation

This commit is contained in:
Dominik Sander 2016-09-13 19:56:52 +02:00
parent 5fbeb105b2
commit 03b628dadb
12 changed files with 141 additions and 141 deletions

View file

@ -6,8 +6,8 @@ describe Admin::UsersController do
it 'imports the default scenario for the new user' do
mock(DefaultScenarioImporter).import(is_a(User))
sign_in users(:jane)
post :create, :user => {username: 'jdoe', email: 'jdoe@example.com',
password: 's3cr3t55', password_confirmation: 's3cr3t55', admin: false }
post :create, params: {:user => {username: 'jdoe', email: 'jdoe@example.com',
password: 's3cr3t55', password_confirmation: 's3cr3t55', admin: false }}
end
end
@ -15,7 +15,7 @@ describe Admin::UsersController do
it 'does not import the default scenario' do
stub(DefaultScenarioImporter).import(is_a(User)) { fail "Should not attempt import" }
sign_in users(:jane)
post :create, :user => {username: 'user'}
post :create, params: {:user => {username: 'user'}}
end
end
end
@ -24,7 +24,7 @@ describe Admin::UsersController do
it "switches to another user" do
sign_in users(:jane)
get :switch_to_user, :id => users(:bob).id
get :switch_to_user, params: {:id => users(:bob).id}
expect(response).to redirect_to(agents_path)
expect(subject.session[:original_admin_user_id]).to eq(users(:jane).id)
end
@ -32,7 +32,7 @@ describe Admin::UsersController do
it "does not switch if not admin" do
sign_in users(:bob)
get :switch_to_user, :id => users(:jane).id
get :switch_to_user, params: {:id => users(:jane).id}
expect(response).to redirect_to(root_path)
end
end
@ -41,7 +41,7 @@ describe Admin::UsersController do
it "switches to another user and back" do
sign_in users(:jane)
get :switch_to_user, :id => users(:bob).id
get :switch_to_user, params: {:id => users(:bob).id}
expect(response).to redirect_to(agents_path)
expect(subject.session[:original_admin_user_id]).to eq(users(:jane).id)

View file

@ -16,7 +16,7 @@ describe Agents::DryRunsController do
describe "GET index" do
it "does not load any events without specifing sources" do
get :index, type: 'Agents::WebsiteAgent', source_ids: []
get :index, params: {type: 'Agents::WebsiteAgent', source_ids: []}
expect(assigns(:events)).to eq([])
end
@ -29,13 +29,13 @@ describe Agents::DryRunsController do
end
it "for new agents" do
get :index, type: 'Agents::WebsiteAgent', source_ids: [@agent.id]
get :index, params: {type: 'Agents::WebsiteAgent', source_ids: [@agent.id]}
expect(assigns(:events)).to eq([])
end
it "for existing agents" do
expect(@agent.events.count).not_to be(0)
expect { get :index, agent_id: @agent }.to raise_error(NoMethodError)
expect { get :index, params: {agent_id: @agent} }.to raise_error(NoMethodError)
end
end
@ -47,12 +47,12 @@ describe Agents::DryRunsController do
end
it "load the most recent events when providing source ids" do
get :index, type: 'Agents::WebsiteAgent', source_ids: [@agent.id]
get :index, params: {type: 'Agents::WebsiteAgent', source_ids: [@agent.id]}
expect(assigns(:events)).to eq([@agent.events.first])
end
it "loads the most recent events for a saved agent" do
get :index, agent_id: @agent
get :index, params: {agent_id: @agent}
expect(assigns(:events)).to eq([@agent.events.first])
end
end
@ -65,7 +65,7 @@ describe Agents::DryRunsController do
it "does not actually create any agent, event or log" do
expect {
post :create, agent: valid_attributes
post :create, params: {agent: valid_attributes}
}.not_to change {
[users(:bob).agents.count, users(:bob).events.count, users(:bob).logs.count]
}
@ -81,7 +81,7 @@ describe Agents::DryRunsController do
it "does not actually update an agent" do
agent = agents(:bob_weather_agent)
expect {
post :create, agent_id: agent, agent: valid_attributes(name: 'New Name')
post :create, params: {agent_id: agent, agent: valid_attributes(name: 'New Name')}
}.not_to change {
[users(:bob).agents.count, users(:bob).events.count, users(:bob).logs.count, agent.name, agent.updated_at]
}
@ -93,7 +93,7 @@ describe Agents::DryRunsController do
agent.save!
url_from_event = "http://xkcd.com/?from_event=1".freeze
expect {
post :create, agent_id: agent, event: { url: url_from_event }
post :create, params: {agent_id: agent, event: { url: url_from_event }}
}.not_to change {
[users(:bob).agents.count, users(:bob).events.count, users(:bob).logs.count, agent.name, agent.updated_at]
}
@ -112,7 +112,7 @@ describe Agents::DryRunsController do
agent.memory = {fu: "bar"}
agent.user = users(:bob)
agent.save!
post :create, agent_id: agent, agent: valid_params
post :create, params: {agent_id: agent, agent: valid_params}
results = assigns(:results)
expect(results[:events][0]).to eql({"message" => "bar"})
end

View file

@ -29,7 +29,7 @@ describe AgentsController do
describe "POST handle_details_post" do
it "passes control to handle_details_post on the agent" do
sign_in users(:bob)
post :handle_details_post, :id => agents(:bob_manual_event_agent).to_param, :payload => { :foo => "bar" }.to_json
post :handle_details_post, params: {:id => agents(:bob_manual_event_agent).to_param, :payload => { :foo => "bar" }.to_json}
expect(JSON.parse(response.body)).to eq({ "success" => true })
expect(agents(:bob_manual_event_agent).events.last.payload).to eq({ 'foo' => "bar" })
end
@ -37,7 +37,7 @@ describe AgentsController do
it "can only be accessed by the Agent's owner" do
sign_in users(:jane)
expect {
post :handle_details_post, :id => agents(:bob_manual_event_agent).to_param, :payload => { :foo => :bar }.to_json
post :handle_details_post, params: {:id => agents(:bob_manual_event_agent).to_param, :payload => { :foo => :bar }.to_json}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@ -46,13 +46,13 @@ describe AgentsController do
it "triggers Agent.async_check with the Agent's ID" do
sign_in users(:bob)
mock(Agent).async_check(agents(:bob_manual_event_agent).id)
post :run, :id => agents(:bob_manual_event_agent).to_param
post :run, params: {:id => agents(:bob_manual_event_agent).to_param}
end
it "can only be accessed by the Agent's owner" do
sign_in users(:jane)
expect {
post :run, :id => agents(:bob_manual_event_agent).to_param
post :run, params: {:id => agents(:bob_manual_event_agent).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@ -62,7 +62,7 @@ describe AgentsController do
sign_in users(:bob)
agent_event = events(:bob_website_agent_event).id
other_event = events(:jane_website_agent_event).id
post :remove_events, :id => agents(:bob_website_agent).to_param
post :remove_events, params: {:id => agents(:bob_website_agent).to_param}
expect(Event.where(:id => agent_event).count).to eq(0)
expect(Event.where(:id => other_event).count).to eq(1)
end
@ -70,7 +70,7 @@ describe AgentsController do
it "can only be accessed by the Agent's owner" do
sign_in users(:jane)
expect {
post :remove_events, :id => agents(:bob_website_agent).to_param
post :remove_events, params: {:id => agents(:bob_website_agent).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@ -110,11 +110,11 @@ describe AgentsController do
describe "GET show" do
it "only shows Agents for the current user" do
sign_in users(:bob)
get :show, :id => agents(:bob_website_agent).to_param
get :show, params: {:id => agents(:bob_website_agent).to_param}
expect(assigns(:agent)).to eq(agents(:bob_website_agent))
expect {
get :show, :id => agents(:jane_website_agent).to_param
get :show, params: {:id => agents(:jane_website_agent).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@ -123,7 +123,7 @@ describe AgentsController do
describe "with :id" do
it "opens a clone of a given Agent" do
sign_in users(:bob)
get :new, :id => agents(:bob_website_agent).to_param
get :new, params: {:id => agents(:bob_website_agent).to_param}
expect(assigns(:agent).attributes).to eq(users(:bob).agents.build_clone(agents(:bob_website_agent)).attributes)
end
@ -131,7 +131,7 @@ describe AgentsController do
sign_in users(:bob)
expect {
get :new, :id => agents(:jane_website_agent).to_param
get :new, params: {:id => agents(:jane_website_agent).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@ -139,13 +139,13 @@ describe AgentsController do
describe "with a scenario_id" do
it 'populates the assigned agent with the scenario' do
sign_in users(:bob)
get :new, :scenario_id => scenarios(:bob_weather).id
get :new, params: {:scenario_id => scenarios(:bob_weather).id}
expect(assigns(:agent).scenario_ids).to eq([scenarios(:bob_weather).id])
end
it "does not see other user's scenarios" do
sign_in users(:bob)
get :new, :scenario_id => scenarios(:jane_weather).id
get :new, params: {:scenario_id => scenarios(:jane_weather).id}
expect(assigns(:agent).scenario_ids).to eq([])
end
end
@ -154,11 +154,11 @@ describe AgentsController do
describe "GET edit" do
it "only shows Agents for the current user" do
sign_in users(:bob)
get :edit, :id => agents(:bob_website_agent).to_param
get :edit, params: {:id => agents(:bob_website_agent).to_param}
expect(assigns(:agent)).to eq(agents(:bob_website_agent))
expect {
get :edit, :id => agents(:jane_website_agent).to_param
get :edit, params: {:id => agents(:jane_website_agent).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@ -167,27 +167,27 @@ describe AgentsController do
it "errors on bad types" do
sign_in users(:bob)
expect {
post :create, :agent => valid_attributes(:type => "Agents::ThisIsFake")
post :create, params: {:agent => valid_attributes(:type => "Agents::ThisIsFake")}
}.not_to change { users(:bob).agents.count }
expect(assigns(:agent)).to be_a(Agent)
expect(assigns(:agent)).to have(1).error_on(:type)
sign_in users(:bob)
expect {
post :create, :agent => valid_attributes(:type => "Object")
post :create, params: {:agent => valid_attributes(:type => "Object")}
}.not_to change { users(:bob).agents.count }
expect(assigns(:agent)).to be_a(Agent)
expect(assigns(:agent)).to have(1).error_on(:type)
sign_in users(:bob)
expect {
post :create, :agent => valid_attributes(:type => "Agent")
post :create, params: {:agent => valid_attributes(:type => "Agent")}
}.not_to change { users(:bob).agents.count }
expect(assigns(:agent)).to be_a(Agent)
expect(assigns(:agent)).to have(1).error_on(:type)
expect {
post :create, :agent => valid_attributes(:type => "User")
post :create, params: {:agent => valid_attributes(:type => "User")}
}.not_to change { users(:bob).agents.count }
expect(assigns(:agent)).to be_a(Agent)
expect(assigns(:agent)).to have(1).error_on(:type)
@ -197,7 +197,7 @@ describe AgentsController do
sign_in users(:bob)
expect {
expect {
post :create, :agent => valid_attributes
post :create, params: {:agent => valid_attributes}
}.to change { users(:bob).agents.count }.by(1)
}.to change { Link.count }.by(1)
expect(assigns(:agent)).to be_a(Agents::WebsiteAgent)
@ -209,7 +209,7 @@ describe AgentsController do
attributes[:receiver_ids] = attributes[:source_ids]
expect {
expect {
post :create, :agent => attributes
post :create, params: {:agent => attributes}
}.to change { users(:bob).agents.count }.by(1)
}.to change { Link.count }.by(2)
expect(assigns(:agent)).to be_a(Agents::WebsiteAgent)
@ -218,7 +218,7 @@ describe AgentsController do
it "shows errors" do
sign_in users(:bob)
expect {
post :create, :agent => valid_attributes(:name => "")
post :create, params: {:agent => valid_attributes(:name => "")}
}.not_to change { users(:bob).agents.count }
expect(assigns(:agent)).to have(1).errors_on(:name)
expect(response).to render_template("new")
@ -228,7 +228,7 @@ describe AgentsController do
sign_in users(:bob)
expect {
expect {
post :create, :agent => valid_attributes(:source_ids => [agents(:jane_weather_agent).id])
post :create, params: {:agent => valid_attributes(:source_ids => [agents(:jane_weather_agent).id])}
}.not_to change { users(:bob).agents.count }
}.not_to change { Link.count }
end
@ -237,25 +237,25 @@ describe AgentsController do
describe "PUT update" do
it "does not allow changing types" do
sign_in users(:bob)
post :update, :id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:type => "Agents::WeatherAgent")
post :update, params: {:id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:type => "Agents::WeatherAgent")}
expect(assigns(:agent)).to have(1).errors_on(:type)
expect(response).to render_template("edit")
end
it "updates attributes on Agents for the current user" do
sign_in users(:bob)
post :update, :id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name")
post :update, params: {:id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name")}
expect(response).to redirect_to(agents_path)
expect(agents(:bob_website_agent).reload.name).to eq("New name")
expect {
post :update, :id => agents(:jane_website_agent).to_param, :agent => valid_attributes(:name => "New name")
post :update, params: {:id => agents(:jane_website_agent).to_param, :agent => valid_attributes(:name => "New name")}
}.to raise_error(ActiveRecord::RecordNotFound)
end
it "accepts JSON requests" do
sign_in users(:bob)
post :update, :id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name"), :format => :json
post :update, params: {:id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name")}, :format => :json
expect(agents(:bob_website_agent).reload.name).to eq("New name")
expect(JSON.parse(response.body)['name']).to eq("New name")
expect(response).to be_success
@ -263,19 +263,19 @@ describe AgentsController do
it "will not accept Agent sources owned by other users" do
sign_in users(:bob)
post :update, :id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:source_ids => [agents(:jane_weather_agent).id])
post :update, params: {:id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:source_ids => [agents(:jane_weather_agent).id])}
expect(assigns(:agent)).to have(1).errors_on(:sources)
end
it "will not accept Scenarios owned by other users" do
sign_in users(:bob)
post :update, :id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:scenario_ids => [scenarios(:jane_weather).id])
post :update, params: {:id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:scenario_ids => [scenarios(:jane_weather).id])}
expect(assigns(:agent)).to have(1).errors_on(:scenarios)
end
it "shows errors" do
sign_in users(:bob)
post :update, :id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "")
post :update, params: {:id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "")}
expect(assigns(:agent)).to have(1).errors_on(:name)
expect(response).to render_template("edit")
end
@ -283,7 +283,7 @@ describe AgentsController do
it 'does not allow to modify the agents user_id' do
sign_in users(:bob)
expect {
post :update, :id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:user_id => users(:jane).id)
post :update, params: {:id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:user_id => users(:jane).id)}
}.to raise_error(ActionController::UnpermittedParameters)
end
@ -293,28 +293,28 @@ describe AgentsController do
end
it "can redirect back to the show path" do
post :update, :id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name"), :return => "show"
post :update, params: {:id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name"), :return => "show"}
expect(response).to redirect_to(agent_path(agents(:bob_website_agent)))
end
it "redirect back to the index path by default" do
post :update, :id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name")
post :update, params: {:id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name")}
expect(response).to redirect_to(agents_path)
end
it "accepts return paths to scenarios" do
post :update, :id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name"), :return => "/scenarios/2"
post :update, params: {:id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name"), :return => "/scenarios/2"}
expect(response).to redirect_to("/scenarios/2")
end
it "sanitizes return paths" do
post :update, :id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name"), :return => "/scenar"
post :update, params: {:id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name"), :return => "/scenar"}
expect(response).to redirect_to(agents_path)
post :update, :id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name"), :return => "http://google.com"
post :update, params: {:id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name"), :return => "http://google.com"}
expect(response).to redirect_to(agents_path)
post :update, :id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name"), :return => "javascript:alert(1)"
post :update, params: {:id => agents(:bob_website_agent).to_param, :agent => valid_attributes(:name => "New name"), :return => "javascript:alert(1)"}
expect(response).to redirect_to(agents_path)
end
end
@ -325,7 +325,7 @@ describe AgentsController do
agent.disabled = true
agent.last_checked_event_id = nil
agent.save!
post :update, id: agents(:bob_website_agent).to_param, agent: { disabled: 'false', drop_pending_events: 'true' }
post :update, params: {id: agents(:bob_website_agent).to_param, agent: { disabled: 'false', drop_pending_events: 'true' }}
agent.reload
expect(agent.disabled).to eq(false)
expect(agent.last_checked_event_id).to eq(Event.maximum(:id))
@ -337,13 +337,13 @@ describe AgentsController do
sign_in users(:bob)
expect(agents(:bob_weather_agent).scenarios).to include(scenarios(:bob_weather))
put :leave_scenario, :id => agents(:bob_weather_agent).to_param, :scenario_id => scenarios(:bob_weather).to_param
put :leave_scenario, params: {:id => agents(:bob_weather_agent).to_param, :scenario_id => scenarios(:bob_weather).to_param}
expect(agents(:bob_weather_agent).scenarios).not_to include(scenarios(:bob_weather))
expect(Scenario.where(:id => scenarios(:bob_weather).id)).to exist
expect {
put :leave_scenario, :id => agents(:jane_weather_agent).to_param, :scenario_id => scenarios(:jane_weather).to_param
put :leave_scenario, params: {:id => agents(:jane_weather_agent).to_param, :scenario_id => scenarios(:jane_weather).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@ -352,25 +352,25 @@ describe AgentsController do
it "destroys only Agents owned by the current user" do
sign_in users(:bob)
expect {
delete :destroy, :id => agents(:bob_website_agent).to_param
delete :destroy, params: {:id => agents(:bob_website_agent).to_param}
}.to change(Agent, :count).by(-1)
expect {
delete :destroy, :id => agents(:jane_website_agent).to_param
delete :destroy, params: {:id => agents(:jane_website_agent).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
it "redirects correctly when the Agent is deleted from the Agent itself" do
sign_in users(:bob)
delete :destroy, :id => agents(:bob_website_agent).to_param
delete :destroy, params: {:id => agents(:bob_website_agent).to_param}
expect(response).to redirect_to agents_path
end
it "redirects correctly when the Agent is deleted from a Scenario" do
sign_in users(:bob)
delete :destroy, :id => agents(:bob_weather_agent).to_param, :return => scenario_path(scenarios(:bob_weather)).to_param
delete :destroy, params: {:id => agents(:bob_weather_agent).to_param, :return => scenario_path(scenarios(:bob_weather)).to_param}
expect(response).to redirect_to scenario_path(scenarios(:bob_weather))
end
end
@ -387,7 +387,7 @@ describe AgentsController do
stub(klass).validate_option { true }
end
post :validate, @params
post :validate, params: @params
expect(response.status).to eq 200
end
@ -396,7 +396,7 @@ describe AgentsController do
stub(klass).validate_option { false }
end
post :validate, @params
post :validate, params: @params
expect(response.status).to eq 403
end
end
@ -407,7 +407,7 @@ describe AgentsController do
stub(klass).complete_option { [{name: 'test', value: 1}] }
end
post :complete, @params
post :complete, params: @params
expect(response.status).to eq 200
expect(response.header['Content-Type']).to include('application/json')
@ -420,7 +420,7 @@ describe AgentsController do
agent = agents(:bob_website_agent)
agent.update!(memory: { "test" => 42 })
sign_in users(:bob)
delete :destroy_memory, id: agent.to_param
delete :destroy_memory, params: {id: agent.to_param}
expect(agent.reload.memory).to eq({})
end
@ -429,7 +429,7 @@ describe AgentsController do
agent.update!(memory: { "test" => 42 })
sign_in users(:bob)
expect {
delete :destroy_memory, id: agent.to_param
delete :destroy_memory, params: {id: agent.to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
expect(agent.reload.memory).to eq({ "test" => 42})
end

View file

@ -15,12 +15,12 @@ describe EventsController do
it "can filter by Agent" do
sign_in users(:bob)
get :index, :agent_id => agents(:bob_website_agent)
get :index, params: {:agent_id => agents(:bob_website_agent)}
expect(assigns(:events).length).to eq(agents(:bob_website_agent).events.length)
expect(assigns(:events).all? {|i| expect(i.agent).to eq(agents(:bob_website_agent)) }).to be_truthy
expect {
get :index, :agent_id => agents(:jane_website_agent)
get :index, params: {:agent_id => agents(:jane_website_agent)}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@ -28,11 +28,11 @@ describe EventsController do
describe "GET show" do
it "only shows Events for the current user" do
sign_in users(:bob)
get :show, :id => events(:bob_website_agent_event).to_param
get :show, params: {:id => events(:bob_website_agent_event).to_param}
expect(assigns(:event)).to eq(events(:bob_website_agent_event))
expect {
get :show, :id => events(:jane_website_agent_event).to_param
get :show, params: {:id => events(:jane_website_agent_event).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@ -45,7 +45,7 @@ describe EventsController do
it "clones and re-emits events" do
expect {
post :reemit, :id => events(:bob_website_agent_event).to_param
post :reemit, params: {:id => events(:bob_website_agent_event).to_param}
}.to change { Event.count }.by(1)
expect(Event.last.payload).to eq(events(:bob_website_agent_event).payload)
expect(Event.last.agent).to eq(events(:bob_website_agent_event).agent)
@ -54,7 +54,7 @@ describe EventsController do
it "can only re-emit Events for the current user" do
expect {
post :reemit, :id => events(:jane_website_agent_event).to_param
post :reemit, params: {:id => events(:jane_website_agent_event).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@ -63,11 +63,11 @@ describe EventsController do
it "only deletes events for the current user" do
sign_in users(:bob)
expect {
delete :destroy, :id => events(:bob_website_agent_event).to_param
delete :destroy, params: {:id => events(:bob_website_agent_event).to_param}
}.to change { Event.count }.by(-1)
expect {
delete :destroy, :id => events(:jane_website_agent_event).to_param
delete :destroy, params: {:id => events(:jane_website_agent_event).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end

View file

@ -37,11 +37,11 @@ describe JobsController do
end
it "destroy a job which is not running" do
expect { delete :destroy, id: @not_running.id }.to change(Delayed::Job, :count).by(-1)
expect { delete :destroy, params: {id: @not_running.id} }.to change(Delayed::Job, :count).by(-1)
end
it "does not destroy a running job" do
expect { delete :destroy, id: @running.id }.to change(Delayed::Job, :count).by(0)
expect { delete :destroy, params: {id: @running.id} }.to change(Delayed::Job, :count).by(0)
end
end
@ -54,15 +54,15 @@ describe JobsController do
end
it "queue a job which is not running" do
expect { put :run, id: @not_running.id }.to change { @not_running.reload.run_at }
expect { put :run, params: {id: @not_running.id} }.to change { @not_running.reload.run_at }
end
it "queue a job that failed" do
expect { put :run, id: @failed.id }.to change { @failed.reload.run_at }
expect { put :run, params: {id: @failed.id} }.to change { @failed.reload.run_at }
end
it "not queue a running job" do
expect { put :run, id: @running.id }.not_to change { @not_running.reload.run_at }
expect { put :run, params: {id: @running.id} }.not_to change { @not_running.reload.run_at }
end
end

View file

@ -4,7 +4,7 @@ describe LogsController do
describe "GET index" do
it "can filter by Agent" do
sign_in users(:bob)
get :index, :agent_id => agents(:bob_weather_agent).id
get :index, params: {:agent_id => agents(:bob_weather_agent).id}
expect(assigns(:logs).length).to eq(agents(:bob_weather_agent).logs.length)
expect(assigns(:logs).all? {|i| expect(i.agent).to eq(agents(:bob_weather_agent)) }).to be_truthy
end
@ -12,7 +12,7 @@ describe LogsController do
it "only loads Agents owned by the current user" do
sign_in users(:bob)
expect {
get :index, :agent_id => agents(:jane_weather_agent).id
get :index, params: {:agent_id => agents(:jane_weather_agent).id}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@ -22,7 +22,7 @@ describe LogsController do
agents(:bob_weather_agent).last_error_log_at = 2.hours.ago
sign_in users(:bob)
expect {
delete :clear, :agent_id => agents(:bob_weather_agent).id
delete :clear, params: {:agent_id => agents(:bob_weather_agent).id}
}.to change { AgentLog.count }.by(-1 * agents(:bob_weather_agent).logs.count)
expect(assigns(:logs).length).to eq(0)
expect(agents(:bob_weather_agent).reload.logs.count).to eq(0)
@ -32,7 +32,7 @@ describe LogsController do
it "only deletes logs for an Agent owned by the current user" do
sign_in users(:bob)
expect {
delete :clear, :agent_id => agents(:jane_weather_agent).id
delete :clear, params: {:agent_id => agents(:jane_weather_agent).id}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end

View file

@ -15,7 +15,7 @@ describe ScenarioImportsController do
describe "POST create" do
it "initializes a ScenarioImport for current_user, passing in params" do
post :create, :scenario_import => { :url => "bad url" }
post :create, params: {:scenario_import => { :url => "bad url" }}
expect(assigns(:scenario_import).user).to eq(users(:bob))
expect(assigns(:scenario_import).url).to eq("bad url")
expect(assigns(:scenario_import)).not_to be_valid

View file

@ -18,34 +18,34 @@ describe ScenariosController do
describe "GET show" do
it "only shows Scenarios for the current user" do
get :show, :id => scenarios(:bob_weather).to_param
get :show, params: {:id => scenarios(:bob_weather).to_param}
expect(assigns(:scenario)).to eq(scenarios(:bob_weather))
expect {
get :show, :id => scenarios(:jane_weather).to_param
get :show, params: {:id => scenarios(:jane_weather).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
it "loads Agents for the requested Scenario" do
get :show, :id => scenarios(:bob_weather).to_param
get :show, params: {:id => scenarios(:bob_weather).to_param}
expect(assigns(:agents).pluck(:id).sort).to eq(scenarios(:bob_weather).agents.pluck(:id).sort)
end
end
describe "GET share" do
it "only displays Scenario share information for the current user" do
get :share, :id => scenarios(:bob_weather).to_param
get :share, params: {:id => scenarios(:bob_weather).to_param}
expect(assigns(:scenario)).to eq(scenarios(:bob_weather))
expect {
get :share, :id => scenarios(:jane_weather).to_param
get :share, params: {:id => scenarios(:jane_weather).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
describe "GET export" do
it "returns a JSON file download from an instantiated AgentsExporter" do
get :export, :id => scenarios(:bob_weather).to_param
get :export, params: {:id => scenarios(:bob_weather).to_param}
expect(assigns(:exporter).options[:name]).to eq(scenarios(:bob_weather).name)
expect(assigns(:exporter).options[:description]).to eq(scenarios(:bob_weather).description)
expect(assigns(:exporter).options[:agents]).to eq(scenarios(:bob_weather).agents)
@ -59,11 +59,11 @@ describe ScenariosController do
end
it "only exports private Scenarios for the current user" do
get :export, :id => scenarios(:bob_weather).to_param
get :export, params: {:id => scenarios(:bob_weather).to_param}
expect(assigns(:scenario)).to eq(scenarios(:bob_weather))
expect {
get :export, :id => scenarios(:jane_weather).to_param
get :export, params: {:id => scenarios(:jane_weather).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
@ -73,14 +73,14 @@ describe ScenariosController do
end
it "exports public scenarios for other users when logged in" do
get :export, :id => scenarios(:jane_weather).to_param
get :export, params: {:id => scenarios(:jane_weather).to_param}
expect(assigns(:scenario)).to eq(scenarios(:jane_weather))
expect(assigns(:exporter).options[:source_url]).to eq(export_scenario_url(scenarios(:jane_weather)))
end
it "exports public scenarios for other users when logged out" do
sign_out :user
get :export, :id => scenarios(:jane_weather).to_param
get :export, params: {:id => scenarios(:jane_weather).to_param}
expect(assigns(:scenario)).to eq(scenarios(:jane_weather))
expect(assigns(:exporter).options[:source_url]).to eq(export_scenario_url(scenarios(:jane_weather)))
end
@ -89,11 +89,11 @@ describe ScenariosController do
describe "GET edit" do
it "only shows Scenarios for the current user" do
get :edit, :id => scenarios(:bob_weather).to_param
get :edit, params: {:id => scenarios(:bob_weather).to_param}
expect(assigns(:scenario)).to eq(scenarios(:bob_weather))
expect {
get :edit, :id => scenarios(:jane_weather).to_param
get :edit, params: {:id => scenarios(:jane_weather).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@ -101,13 +101,13 @@ describe ScenariosController do
describe "POST create" do
it "creates Scenarios for the current user" do
expect {
post :create, :scenario => valid_attributes
post :create, params: {:scenario => valid_attributes}
}.to change { users(:bob).scenarios.count }.by(1)
end
it "shows errors" do
expect {
post :create, :scenario => valid_attributes(:name => "")
post :create, params: {:scenario => valid_attributes(:name => "")}
}.not_to change { users(:bob).scenarios.count }
expect(assigns(:scenario)).to have(1).errors_on(:name)
expect(response).to render_template("new")
@ -115,33 +115,33 @@ describe ScenariosController do
it "will not create Scenarios for other users" do
expect {
post :create, :scenario => valid_attributes(:user_id => users(:jane).id)
post :create, params: {:scenario => valid_attributes(:user_id => users(:jane).id)}
}.to raise_error(ActionController::UnpermittedParameters)
end
end
describe "PUT update" do
it "updates attributes on Scenarios for the current user" do
post :update, :id => scenarios(:bob_weather).to_param, :scenario => { :name => "new_name", :public => "1" }
post :update, params: {:id => scenarios(:bob_weather).to_param, :scenario => { :name => "new_name", :public => "1" }}
expect(response).to redirect_to(scenario_path(scenarios(:bob_weather)))
expect(scenarios(:bob_weather).reload.name).to eq("new_name")
expect(scenarios(:bob_weather)).to be_public
expect {
post :update, :id => scenarios(:jane_weather).to_param, :scenario => { :name => "new_name" }
post :update, params: {:id => scenarios(:jane_weather).to_param, :scenario => { :name => "new_name" }}
}.to raise_error(ActiveRecord::RecordNotFound)
expect(scenarios(:jane_weather).reload.name).not_to eq("new_name")
end
it "shows errors" do
post :update, :id => scenarios(:bob_weather).to_param, :scenario => { :name => "" }
post :update, params: {:id => scenarios(:bob_weather).to_param, :scenario => { :name => "" }}
expect(assigns(:scenario)).to have(1).errors_on(:name)
expect(response).to render_template("edit")
end
it 'adds an agent to the scenario' do
expect {
post :update, :id => scenarios(:bob_weather).to_param, :scenario => { :name => "new_name", :public => "1", agent_ids: scenarios(:bob_weather).agent_ids + [agents(:bob_website_agent).id] }
post :update, params: {:id => scenarios(:bob_weather).to_param, :scenario => { :name => "new_name", :public => "1", agent_ids: scenarios(:bob_weather).agent_ids + [agents(:bob_website_agent).id] }}
}.to change { scenarios(:bob_weather).agent_ids.length }.by(1)
end
end
@ -149,7 +149,7 @@ describe ScenariosController do
describe 'PUT enable_or_disable_all_agents' do
it 'updates disabled on all agents in a scenario for the current user' do
@params = {"scenario"=>{"disabled"=>"true"}, "commit"=>"Yes", "id"=> scenarios(:bob_weather).id}
put :enable_or_disable_all_agents, @params
put :enable_or_disable_all_agents, params: @params
expect(agents(:bob_rain_notifier_agent).disabled).to eq(true)
expect(response).to redirect_to(scenario_path(scenarios(:bob_weather)))
end
@ -158,17 +158,17 @@ describe ScenariosController do
describe "DELETE destroy" do
it "destroys only Scenarios owned by the current user" do
expect {
delete :destroy, :id => scenarios(:bob_weather).to_param
delete :destroy, params: {:id => scenarios(:bob_weather).to_param}
}.to change(Scenario, :count).by(-1)
expect {
delete :destroy, :id => scenarios(:jane_weather).to_param
delete :destroy, params: {:id => scenarios(:jane_weather).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
it "passes the mode to the model" do
expect {
delete :destroy, id: scenarios(:bob_weather).to_param, mode: 'all_agents'
delete :destroy, params: {id: scenarios(:bob_weather).to_param, mode: 'all_agents'}
}.to change(Agent, :count).by(-2)
end
end

View file

@ -14,14 +14,14 @@ describe ServicesController do
describe "POST toggle_availability" do
it "should work for service of the user" do
post :toggle_availability, :id => services(:generic).to_param
post :toggle_availability, params: {:id => services(:generic).to_param}
expect(assigns(:service)).to eq(services(:generic))
redirect_to(services_path)
end
it "should not work for a service of another user" do
expect {
post :toggle_availability, :id => services(:global).to_param
post :toggle_availability, params: {:id => services(:global).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@ -29,11 +29,11 @@ describe ServicesController do
describe "DELETE destroy" do
it "destroys only services owned by the current user" do
expect {
delete :destroy, :id => services(:generic).to_param
delete :destroy, params: {:id => services(:generic).to_param}
}.to change(Service, :count).by(-1)
expect {
delete :destroy, :id => services(:global).to_param
delete :destroy, params: {:id => services(:global).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end

View file

@ -22,30 +22,30 @@ describe UserCredentialsController do
describe "GET edit" do
it "only shows UserCredentials for the current user" do
get :edit, :id => user_credentials(:bob_aws_secret).to_param
get :edit, params: {:id => user_credentials(:bob_aws_secret).to_param}
expect(assigns(:user_credential)).to eq(user_credentials(:bob_aws_secret))
expect {
get :edit, :id => user_credentials(:jane_aws_secret).to_param
get :edit, params: {:id => user_credentials(:jane_aws_secret).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
describe "Post import" do
it "asserts user credentials were created for current user only" do
post :import, :file => @file
post :import, params: {:file => @file}
expect(controller.current_user.id).to eq(users(:bob).id)
expect(controller.current_user.user_credentials).to eq(users(:bob).user_credentials)
end
it "asserts that primary id in json file is ignored" do
post :import, :file => @file
post :import, params: {:file => @file}
expect(controller.current_user.user_credentials.last.id).not_to eq(24)
end
it "duplicate credential name shows an error that it is not saved" do
file1 = fixture_file_upload('multiple_user_credentials.json')
post :import, :file => file1
post :import, params: {:file => file1}
expect(flash[:notice]).to eq("One or more of the uploaded credentials was not imported due to an error. Perhaps an existing credential had the same name?")
expect(response).to redirect_to(user_credentials_path)
end
@ -54,13 +54,13 @@ describe UserCredentialsController do
describe "POST create" do
it "creates UserCredentials for the current user" do
expect {
post :create, :user_credential => valid_attributes
post :create, params: {:user_credential => valid_attributes}
}.to change { users(:bob).user_credentials.count }.by(1)
end
it "shows errors" do
expect {
post :create, :user_credential => valid_attributes(:credential_name => "")
post :create, params: {:user_credential => valid_attributes(:credential_name => "")}
}.not_to change { users(:bob).user_credentials.count }
expect(assigns(:user_credential)).to have(1).errors_on(:credential_name)
expect(response).to render_template("new")
@ -68,25 +68,25 @@ describe UserCredentialsController do
it "will not create UserCredentials for other users" do
expect {
post :create, :user_credential => valid_attributes(:user_id => users(:jane).id)
post :create, params: {:user_credential => valid_attributes(:user_id => users(:jane).id)}
}.to raise_error(ActionController::UnpermittedParameters)
end
end
describe "PUT update" do
it "updates attributes on UserCredentials for the current user" do
post :update, :id => user_credentials(:bob_aws_key).to_param, :user_credential => { :credential_name => "new_name" }
post :update, params: {:id => user_credentials(:bob_aws_key).to_param, :user_credential => { :credential_name => "new_name" }}
expect(response).to redirect_to(user_credentials_path)
expect(user_credentials(:bob_aws_key).reload.credential_name).to eq("new_name")
expect {
post :update, :id => user_credentials(:jane_aws_key).to_param, :user_credential => { :credential_name => "new_name" }
post :update, params: {:id => user_credentials(:jane_aws_key).to_param, :user_credential => { :credential_name => "new_name" }}
}.to raise_error(ActiveRecord::RecordNotFound)
expect(user_credentials(:jane_aws_key).reload.credential_name).not_to eq("new_name")
end
it "shows errors" do
post :update, :id => user_credentials(:bob_aws_key).to_param, :user_credential => { :credential_name => "" }
post :update, params: {:id => user_credentials(:bob_aws_key).to_param, :user_credential => { :credential_name => "" }}
expect(assigns(:user_credential)).to have(1).errors_on(:credential_name)
expect(response).to render_template("edit")
end
@ -95,11 +95,11 @@ describe UserCredentialsController do
describe "DELETE destroy" do
it "destroys only UserCredentials owned by the current user" do
expect {
delete :destroy, :id => user_credentials(:bob_aws_key).to_param
delete :destroy, params: {:id => user_credentials(:bob_aws_key).to_param}
}.to change(UserCredential, :count).by(-1)
expect {
delete :destroy, :id => user_credentials(:jane_aws_key).to_param
delete :destroy, params: {:id => user_credentials(:jane_aws_key).to_param}
}.to raise_error(ActiveRecord::RecordNotFound)
end
end

View file

@ -2,8 +2,6 @@ require 'rails_helper'
module Users
describe RegistrationsController do
include Devise::TestHelpers
describe "POST create" do
before do
@request.env["devise.mapping"] = Devise.mappings[:user]
@ -13,8 +11,10 @@ module Users
it "imports the default scenario for the new user" do
mock(DefaultScenarioImporter).import(is_a(User))
post :create, :user => {username: 'jdoe', email: 'jdoe@example.com',
password: 's3cr3t55', password_confirmation: 's3cr3t55', invitation_code: 'try-huginn'}
post :create, params: {
:user => {username: 'jdoe', email: 'jdoe@example.com',
password: 's3cr3t55', password_confirmation: 's3cr3t55', invitation_code: 'try-huginn'}
}
end
end
@ -23,11 +23,11 @@ module Users
stub(DefaultScenarioImporter).import(is_a(User)) { fail "Should not attempt import" }
setup_controller_for_warden
post :create, :user => {}
post :create, params: {:user => {}}
end
it 'does not allow to set the admin flag' do
expect { post :create, :user => {admin: 'true'} }.to raise_error(ActionController::UnpermittedParameters)
expect { post :create, params: {:user => {admin: 'true'}} }.to raise_error(ActionController::UnpermittedParameters)
end
end
end

View file

@ -26,14 +26,14 @@ describe WebRequestsController do
it "should not require login to receive a web request" do
expect(@agent.last_web_request_at).to be_nil
post :handle_request, :user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "my_secret", :key => "value", :another_key => "5"
post :handle_request, params: {:user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "my_secret", :key => "value", :another_key => "5"}
expect(@agent.reload.last_web_request_at).to be_within(2).of(Time.now)
expect(response.body).to eq("success")
expect(response).to be_success
end
it "should call receive_web_request" do
post :handle_request, :user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "my_secret", :key => "value", :another_key => "5"
post :handle_request, params: {:user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "my_secret", :key => "value", :another_key => "5"}
@agent.reload
expect(@agent.memory[:web_request_values]).to eq({ 'key' => "value", 'another_key' => "5" })
expect(@agent.memory[:web_request_format]).to eq("text/html")
@ -42,14 +42,14 @@ describe WebRequestsController do
expect(response.headers['Content-Type']).to eq('text/plain; charset=utf-8')
expect(response).to be_success
post :handle_request, :user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "not_my_secret", :no => "go"
post :handle_request, params: {:user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "not_my_secret", :no => "go"}
expect(@agent.reload.memory[:web_request_values]).not_to eq({ 'no' => "go" })
expect(response.body).to eq("failure")
expect(response).to be_missing
end
it "should accept gets" do
get :handle_request, :user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "my_secret", :key => "value", :another_key => "5"
get :handle_request, params: {:user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "my_secret", :key => "value", :another_key => "5"}
@agent.reload
expect(@agent.memory[:web_request_values]).to eq({ 'key' => "value", 'another_key' => "5" })
expect(@agent.memory[:web_request_format]).to eq("text/html")
@ -59,19 +59,19 @@ describe WebRequestsController do
end
it "should pass through the received format" do
get :handle_request, :user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "my_secret", :key => "value", :another_key => "5", :format => :json
get :handle_request, params: {:user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "my_secret", :key => "value", :another_key => "5"}, :format => :json
@agent.reload
expect(@agent.memory[:web_request_values]).to eq({ 'key' => "value", 'another_key' => "5" })
expect(@agent.memory[:web_request_format]).to eq("application/json")
expect(@agent.memory[:web_request_method]).to eq("get")
post :handle_request, :user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "my_secret", :key => "value", :another_key => "5", :format => :xml
post :handle_request, params: {:user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "my_secret", :key => "value", :another_key => "5"}, :format => :xml
@agent.reload
expect(@agent.memory[:web_request_values]).to eq({ 'key' => "value", 'another_key' => "5" })
expect(@agent.memory[:web_request_format]).to eq("application/xml")
expect(@agent.memory[:web_request_method]).to eq("post")
put :handle_request, :user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "my_secret", :key => "value", :another_key => "5", :format => :atom
put :handle_request, params: {:user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "my_secret", :key => "value", :another_key => "5"}, :format => :atom
@agent.reload
expect(@agent.memory[:web_request_values]).to eq({ 'key' => "value", 'another_key' => "5" })
expect(@agent.memory[:web_request_format]).to eq("application/atom+xml")
@ -81,17 +81,17 @@ describe WebRequestsController do
it "can accept a content-type to return" do
@agent.memory['content_type'] = 'application/json'
@agent.save!
get :handle_request, :user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "my_secret", :key => "value", :another_key => "5"
get :handle_request, params: {:user_id => users(:bob).to_param, :agent_id => @agent.id, :secret => "my_secret", :key => "value", :another_key => "5"}
expect(response.headers['Content-Type']).to eq('application/json; charset=utf-8')
end
it "should fail on incorrect users" do
post :handle_request, :user_id => users(:jane).to_param, :agent_id => @agent.id, :secret => "my_secret", :no => "go"
post :handle_request, params: {:user_id => users(:jane).to_param, :agent_id => @agent.id, :secret => "my_secret", :no => "go"}
expect(response).to be_missing
end
it "should fail on incorrect agents" do
post :handle_request, :user_id => users(:bob).to_param, :agent_id => 454545, :secret => "my_secret", :no => "go"
post :handle_request, params: {:user_id => users(:bob).to_param, :agent_id => 454545, :secret => "my_secret", :no => "go"}
expect(response).to be_missing
end
@ -102,7 +102,7 @@ describe WebRequestsController do
end
it "should create events without requiring login" do
post :update_location, user_id: users(:bob).to_param, secret: "my_secret", longitude: 123, latitude: 45, something: "else"
post :update_location, params: {user_id: users(:bob).to_param, secret: "my_secret", longitude: 123, latitude: 45, something: "else"}
expect(@agent.events.last.payload).to eq({ 'longitude' => "123", 'latitude' => "45", 'something' => "else" })
expect(@agent.events.last.lat).to eq(45)
expect(@agent.events.last.lng).to eq(123)
@ -112,13 +112,13 @@ describe WebRequestsController do
@jane_agent = Agent.build_for_type("Agents::UserLocationAgent", users(:jane), name: "something", options: { secret: "my_secret" })
@jane_agent.save!
post :update_location, user_id: users(:bob).to_param, secret: "my_secret", longitude: 123, latitude: 45, something: "else"
post :update_location, params: {user_id: users(:bob).to_param, secret: "my_secret", longitude: 123, latitude: 45, something: "else"}
expect(@agent.events.last.payload).to eq({ 'longitude' => "123", 'latitude' => "45", 'something' => "else" })
expect(@jane_agent.events).to be_empty
end
it "should raise a 404 error when given an invalid user id" do
post :update_location, user_id: "123", secret: "not_my_secret", longitude: 123, latitude: 45, something: "else"
post :update_location, params: {user_id: "123", secret: "not_my_secret", longitude: 123, latitude: 45, something: "else"}
expect(response).to be_missing
end
@ -127,7 +127,7 @@ describe WebRequestsController do
@agent2.save!
expect {
post :update_location, user_id: users(:bob).to_param, secret: "my_secret2", longitude: 123, latitude: 45, something: "else"
post :update_location, params: {user_id: users(:bob).to_param, secret: "my_secret2", longitude: 123, latitude: 45, something: "else"}
expect(@agent2.events.last.payload).to eq({ 'longitude' => "123", 'latitude' => "45", 'something' => "else" })
}.not_to change { @agent.events.count }
end