diff --git a/spec/controllers/admin/pods_controller_spec.rb b/spec/controllers/admin/pods_controller_spec.rb index 9244351ee2063c8b27a1f82c6504f3361c684e5d..784e29c6e30a79bc48de274fabe36fd3cd83e5ad 100644 --- a/spec/controllers/admin/pods_controller_spec.rb +++ b/spec/controllers/admin/pods_controller_spec.rb @@ -38,12 +38,12 @@ describe Admin::PodsController, type: :controller do end it "performs a connection test" do - post :recheck, pod_id: 1 + post :recheck, params: {pod_id: 1} expect(response).to be_redirect end it "performs a connection test (format: json)" do - post :recheck, pod_id: 1, format: :json + post :recheck, params: {pod_id: 1}, format: :json expect(response.body).to eql(PodPresenter.new(@pod).to_json) end end diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index e96fa750ec8041ba86fb34ab6d823fedb16f0e48..7293ffab2b59d580f3ea8b5b01df5c56853d0367 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -12,7 +12,7 @@ describe Admin::UsersController, :type => :controller do expect(other_user).to receive(:close_account!) allow(User).to receive(:find).and_return(other_user) - post :close_account, id: other_user.id + post :close_account, params: {id: other_user.id} end end diff --git a/spec/controllers/admins_controller_spec.rb b/spec/controllers/admins_controller_spec.rb index 4dfdd0ef5ad28ff9ac6947a9ee7536824c061505..e9580a5d26a790c6e7860bc1221c1464ae2bfc7c 100644 --- a/spec/controllers/admins_controller_spec.rb +++ b/spec/controllers/admins_controller_spec.rb @@ -70,12 +70,12 @@ describe AdminsController, :type => :controller do end it 'searches on username' do - get :user_search, admins_controller_user_search: { username: @user.username } + get :user_search, params: {admins_controller_user_search: {username: @user.username}} expect(assigns[:users]).to eq([@user]) end it 'searches on email' do - get :user_search, admins_controller_user_search: { email: @user.email } + get :user_search, params: {admins_controller_user_search: {email: @user.email}} expect(assigns[:users]).to eq([@user]) end @@ -88,7 +88,7 @@ describe AdminsController, :type => :controller do o_13.profile.birthday = 20.years.ago.to_date o_13.profile.save! - get :user_search, admins_controller_user_search: { under13: '1' } + get :user_search, params: {admins_controller_user_search: {under13: "1"}} expect(assigns[:users]).to include(u_13) expect(assigns[:users]).not_to include(o_13) @@ -110,20 +110,20 @@ describe AdminsController, :type => :controller do end it 'does not die if you do it twice' do - get :admin_inviter, :identifier => 'bob@moms.com' - get :admin_inviter, :identifier => 'bob@moms.com' + get :admin_inviter, params: {identifier: "bob@moms.com"} + get :admin_inviter, params: {identifier: "bob@moms.com"} expect(response).to be_redirect end it 'invites a new user' do expect(EmailInviter).to receive(:new).and_return(double.as_null_object) - get :admin_inviter, :identifier => 'bob@moms.com' + get :admin_inviter, params: {identifier: "bob@moms.com"} expect(response).to redirect_to user_search_path expect(flash.notice).to include("invitation sent") end it "doesn't invite an existing user" do - get :admin_inviter, identifier: bob.email + get :admin_inviter, params: {identifier: bob.email} expect(response).to redirect_to user_search_path expect(flash.notice).to include("error sending invite") end @@ -148,7 +148,7 @@ describe AdminsController, :type => :controller do it "succeeds and renders stats for different ranges" do %w(week 2weeks month).each do |range| - get :stats, range: range + get :stats, params: {range: range} expect(response).to be_success expect(response).to render_template(:stats) expect(response.body).not_to include( diff --git a/spec/controllers/api/openid_connect/authorizations_controller_spec.rb b/spec/controllers/api/openid_connect/authorizations_controller_spec.rb index f32ae09570e4ece2ac85e6d67f3f8b3fbaed26ea..51d6e40ca136c6e7d3d98be8d9dadcd8c3f6966a 100644 --- a/spec/controllers/api/openid_connect/authorizations_controller_spec.rb +++ b/spec/controllers/api/openid_connect/authorizations_controller_spec.rb @@ -12,19 +12,19 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do context "when valid parameters are passed" do context "as GET request" do it "should return a form page" do - get new_api_openid_connect_authorization_path, client_id: client.client_id, + get new_api_openid_connect_authorization_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", response_type: "id_token", - scope: "openid", nonce: SecureRandom.hex(16), state: SecureRandom.hex(16) + scope: "openid", nonce: SecureRandom.hex(16), state: SecureRandom.hex(16)} expect(response.body).to match("Diaspora Test Client") end end context "using claims" do it "should return a form page" do - get new_api_openid_connect_authorization_path, client_id: client.client_id, + get new_api_openid_connect_authorization_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", response_type: "id_token", scope: "openid", claims: "{\"userinfo\": {\"name\": {\"essential\": true}}}", - nonce: SecureRandom.hex(16), state: SecureRandom.hex(16) + nonce: SecureRandom.hex(16), state: SecureRandom.hex(16)} expect(response.body).to match("Diaspora Test Client") end end @@ -37,9 +37,9 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do claims: {userinfo: {name: {essential: true}}}} payload = JWT.encoded_payload(JSON.parse(payload_hash.to_json)) request_object = header + "." + payload + "." - get new_api_openid_connect_authorization_path, client_id: client.client_id, + get new_api_openid_connect_authorization_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", response_type: "id_token", - scope: "openid", nonce: "hello", state: "hello", request: request_object + scope: "openid", nonce: "hello", state: "hello", request: request_object} expect(response.body).to match("Diaspora Test Client") end end @@ -51,18 +51,18 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do response_type: "id_token", scope: "openid", nonce: "hello", state: "hello"} payload = JWT.encoded_payload(JSON.parse(payload_hash.to_json)) request_object = header + "." + payload + "." - get new_api_openid_connect_authorization_path, client_id: client.client_id, + get new_api_openid_connect_authorization_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", response_type: "id_token", - scope: "openid", nonce: "hello", state: "hello", request: request_object + scope: "openid", nonce: "hello", state: "hello", request: request_object} expect(response.body).to match("Diaspora Test Client") end end context "as POST request" do it "should return a form page" do - post api_openid_connect_authorizations_new_path, client_id: client.client_id, + post api_openid_connect_authorizations_new_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", response_type: "id_token", - scope: "openid", nonce: SecureRandom.hex(16), state: SecureRandom.hex(16) + scope: "openid", nonce: SecureRandom.hex(16), state: SecureRandom.hex(16)} expect(response.body).to match("Diaspora Test Client") end end @@ -70,9 +70,8 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do context "when client id is missing" do it "should return an bad request error" do - post api_openid_connect_authorizations_new_path, - redirect_uri: "http://localhost:3000/", response_type: "id_token", - scope: "openid", nonce: SecureRandom.hex(16), state: SecureRandom.hex(16) + post api_openid_connect_authorizations_new_path, params: {redirect_uri: "http://localhost:3000/", + response_type: "id_token", scope: "openid", nonce: SecureRandom.hex(16), state: SecureRandom.hex(16)} expect(response.body).to include("The request was malformed") end end @@ -84,8 +83,8 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do # When client has only one redirect uri registered, only that redirect uri can be used. Hence, # we should implicitly assume the client wants to use that registered URI. # See https://github.com/nov/rack-oauth2/blob/master/lib/rack/oauth2/server/authorize.rb#L63 - post api_openid_connect_authorizations_new_path, client_id: client.client_id, response_type: "id_token", - scope: "openid", nonce: SecureRandom.hex(16), state: SecureRandom.hex(16) + post api_openid_connect_authorizations_new_path, params: {client_id: client.client_id, + response_type: "id_token", scope: "openid", nonce: SecureRandom.hex(16), state: SecureRandom.hex(16)} expect(response.body).to match("Diaspora Test Client") end end @@ -93,45 +92,44 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do context "when multiple redirect URLs are pre-registered" do it "should return an invalid request error" do - post api_openid_connect_authorizations_new_path, client_id: client_with_multiple_redirects.client_id, - response_type: "id_token", - scope: "openid", nonce: SecureRandom.hex(16), state: SecureRandom.hex(16) + post api_openid_connect_authorizations_new_path, params: {client_id: client_with_multiple_redirects.client_id, + response_type: "id_token", scope: "openid", nonce: SecureRandom.hex(16), state: SecureRandom.hex(16)} expect(response.body).to include("The request was malformed") end end context "when redirect URI does not match pre-registered URIs" do it "should return an invalid request error" do - post api_openid_connect_authorizations_new_path, client_id: client.client_id, + post api_openid_connect_authorizations_new_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:2000/", - response_type: "id_token", scope: "openid", nonce: SecureRandom.hex(16) + response_type: "id_token", scope: "openid", nonce: SecureRandom.hex(16)} expect(response.body).to include("Invalid client id or redirect uri") end end context "when an unsupported scope is passed in" do it "should return an invalid scope error" do - post api_openid_connect_authorizations_new_path, client_id: client.client_id, + post api_openid_connect_authorizations_new_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", response_type: "id_token", - scope: "random", nonce: SecureRandom.hex(16), state: SecureRandom.hex(16) + scope: "random", nonce: SecureRandom.hex(16), state: SecureRandom.hex(16)} expect(response.body).to match("error=invalid_scope") end end context "when nonce is missing" do it "should return an invalid request error" do - post api_openid_connect_authorizations_new_path, client_id: client.client_id, + post api_openid_connect_authorizations_new_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", - response_type: "id_token", scope: "openid", state: SecureRandom.hex(16) + response_type: "id_token", scope: "openid", state: SecureRandom.hex(16)} expect(response.location).to match("error=invalid_request") end end context "when prompt is none" do it "should return an interaction required error" do - post api_openid_connect_authorizations_new_path, client_id: client.client_id, + post api_openid_connect_authorizations_new_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", - response_type: "id_token", scope: "openid", state: 1234, display: "page", prompt: "none" + response_type: "id_token", scope: "openid", state: 1234, display: "page", prompt: "none"} expect(response.body).to include("User must already be authorized when `prompt` is `none`") end end @@ -142,27 +140,27 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do end it "should return an interaction required error" do - post api_openid_connect_authorizations_new_path, client_id: client.client_id, + post api_openid_connect_authorizations_new_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", - response_type: "id_token", scope: "openid", state: 1234, display: "page", prompt: "none" + response_type: "id_token", scope: "openid", state: 1234, display: "page", prompt: "none"} expect(response.body).to include("User must already be logged in when `prompt` is `none`") end end context "when prompt is none and consent" do it "should return an interaction required error" do - post api_openid_connect_authorizations_new_path, client_id: client.client_id, + post api_openid_connect_authorizations_new_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", - response_type: "id_token", scope: "openid", state: 1234, display: "page", prompt: "none consent" + response_type: "id_token", scope: "openid", state: 1234, display: "page", prompt: "none consent"} expect(response.location).to match("error=invalid_request") end end context "when prompt is select_account" do it "should return an account_selection_required error" do - post api_openid_connect_authorizations_new_path, client_id: client.client_id, + post api_openid_connect_authorizations_new_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", - response_type: "id_token", scope: "openid", state: 1234, display: "page", prompt: "select_account" + response_type: "id_token", scope: "openid", state: 1234, display: "page", prompt: "select_account"} expect(response.location).to match("error=account_selection_required") expect(response.location).to match("state=1234") end @@ -170,26 +168,27 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do context "when prompt is none and client ID is invalid" do it "should return an account_selection_required error" do - post api_openid_connect_authorizations_new_path, client_id: "random", redirect_uri: "http://localhost:3000/", - response_type: "id_token", scope: "openid", state: 1234, display: "page", prompt: "none" + post api_openid_connect_authorizations_new_path, params: {client_id: "random", + redirect_uri: "http://localhost:3000/", response_type: "id_token", scope: "openid", state: 1234, + display: "page", prompt: "none"} expect(response.body).to include("Invalid client id or redirect uri") end end context "when prompt is none and redirect URI does not match pre-registered URIs" do it "should return an account_selection_required error" do - post api_openid_connect_authorizations_new_path, client_id: client.client_id, + post api_openid_connect_authorizations_new_path, params: {client_id: client.client_id, redirect_uri: "http://randomuri:3000/", - response_type: "id_token", scope: "openid", state: 1234, display: "page", prompt: "none" + response_type: "id_token", scope: "openid", state: 1234, display: "page", prompt: "none"} expect(response.body).to include("Invalid client id or redirect uri") end end context "when XSS script is passed as name" do it "should escape html" do - post api_openid_connect_authorizations_new_path, client_id: client_with_xss.client_id, + post api_openid_connect_authorizations_new_path, params: {client_id: client_with_xss.client_id, redirect_uri: "http://localhost:3000/", - response_type: "id_token", scope: "openid", nonce: SecureRandom.hex(16), state: SecureRandom.hex(16) + response_type: "id_token", scope: "openid", nonce: SecureRandom.hex(16), state: SecureRandom.hex(16)} expect(response.body).to_not include("<script>alert(0);</script>") end end @@ -203,9 +202,9 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do context "when valid parameters are passed" do before do - get new_api_openid_connect_authorization_path, client_id: client.client_id, + get new_api_openid_connect_authorization_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", response_type: "id_token", - scope: "openid", nonce: 413_093_098_3, state: 413_093_098_3 + scope: "openid", nonce: 413_093_098_3, state: 413_093_098_3} end it "should return the id token in a fragment" do @@ -224,10 +223,10 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do context "when prompt is none" do it "should return the id token in a fragment" do - post api_openid_connect_authorizations_new_path, client_id: client.client_id, + post api_openid_connect_authorizations_new_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", response_type: "id_token", scope: "openid", nonce: 413_093_098_3, state: 413_093_098_3, - display: "page", prompt: "none" + display: "page", prompt: "none"} expect(response.location).to include("id_token=") encoded_id_token = response.location[/(?<=id_token=)[^&]+/] decoded_token = OpenIDConnect::ResponseObject::IdToken.decode encoded_id_token, @@ -239,19 +238,19 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do context "when prompt contains consent" do it "should return a consent form page" do - get new_api_openid_connect_authorization_path, client_id: client.client_id, + get new_api_openid_connect_authorization_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", response_type: "id_token", scope: "openid", nonce: 413_093_098_3, state: 413_093_098_3, - display: "page", prompt: "consent" + display: "page", prompt: "consent"} expect(response.body).to match("Diaspora Test Client") end end context "when scopes are escalated" do before do - get new_api_openid_connect_authorization_path, client_id: client.client_id, + get new_api_openid_connect_authorization_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", response_type: "id_token", - scope: "openid read", nonce: 413_093_098_3, state: 413_093_098_3 + scope: "openid read", nonce: 413_093_098_3, state: 413_093_098_3} end it "should receive another authorization request" do @@ -259,7 +258,7 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do end it "should overwrite old authorization scope after approval" do - post api_openid_connect_authorizations_path, approve: "true" + post api_openid_connect_authorizations_path, params: {approve: "true"} authorization_with_old_scope = Api::OpenidConnect::Authorization.find_by_client_id_user_and_scopes(client.client_id, alice, ["openid"]) expect(authorization_with_old_scope).to be_nil @@ -271,14 +270,14 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do describe "#create" do context "when id_token token" do before do - get new_api_openid_connect_authorization_path, client_id: client.client_id, + get new_api_openid_connect_authorization_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", response_type: "id_token token", - scope: "openid", nonce: 418_093_098_3, state: 418_093_098_3 + scope: "openid", nonce: 418_093_098_3, state: 418_093_098_3} end context "when authorization is approved" do before do - post api_openid_connect_authorizations_path, approve: "true" + post api_openid_connect_authorizations_path, params: {approve: "true"} end it "should return the id token in a fragment" do @@ -302,14 +301,14 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do context "when id_token" do before do - get new_api_openid_connect_authorization_path, client_id: client.client_id, + get new_api_openid_connect_authorization_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", response_type: "id_token", - scope: "openid", nonce: 418_093_098_3, state: 418_093_098_3 + scope: "openid", nonce: 418_093_098_3, state: 418_093_098_3} end context "when authorization is approved" do before do - post api_openid_connect_authorizations_path, approve: "true" + post api_openid_connect_authorizations_path, params: {approve: "true"} end it "should return the id token in a fragment" do @@ -328,7 +327,7 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do context "when authorization is denied" do before do - post api_openid_connect_authorizations_path, approve: "false" + post api_openid_connect_authorizations_path, params: {approve: "false"} end it "should return an error in the fragment" do @@ -343,14 +342,14 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do context "when code" do before do - get new_api_openid_connect_authorization_path, client_id: client.client_id, + get new_api_openid_connect_authorization_path, params: {client_id: client.client_id, redirect_uri: "http://localhost:3000/", response_type: "code", - scope: "openid", nonce: 418_093_098_3, state: 418_093_098_3 + scope: "openid", nonce: 418_093_098_3, state: 418_093_098_3} end context "when authorization is approved" do before do - post api_openid_connect_authorizations_path, approve: "true" + post api_openid_connect_authorizations_path, params: {approve: "true"} end it "should return the code" do @@ -364,7 +363,7 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do context "when authorization is denied" do before do - post api_openid_connect_authorizations_path, approve: "false" + post api_openid_connect_authorizations_path, params: {approve: "false"} end it "should return an error" do @@ -379,14 +378,10 @@ describe Api::OpenidConnect::AuthorizationsController, type: :request do end describe "#destroy" do - let!(:auth_with_read) { FactoryGirl.create(:auth_with_read) } - context "with existent authorization" do - before do - delete api_openid_connect_authorization_path(auth_with_read.id) - end - it "removes the authorization" do + auth_with_read = FactoryGirl.create(:auth_with_read, o_auth_application: client) + delete api_openid_connect_authorization_path(auth_with_read.id) expect(Api::OpenidConnect::Authorization.find_by(id: auth_with_read.id)).to be_nil end end diff --git a/spec/controllers/api/openid_connect/clients_controller_spec.rb b/spec/controllers/api/openid_connect/clients_controller_spec.rb index a12ad43b893d5c1c139747ec318ed58f0db3ac55..33776fdfbbd5f7dc2b6ba4290c73f89282968f70 100644 --- a/spec/controllers/api/openid_connect/clients_controller_spec.rb +++ b/spec/controllers/api/openid_connect/clients_controller_spec.rb @@ -9,11 +9,11 @@ describe Api::OpenidConnect::ClientsController, type: :controller, suppress_csrf "User-Agent" => "Faraday v0.11.0" }) .to_return(status: 200, body: "[\"http://localhost\"]", headers: {}) - post :create, redirect_uris: ["http://localhost"], client_name: "diaspora client", + post :create, params: {redirect_uris: ["http://localhost"], client_name: "diaspora client", response_types: [], grant_types: [], application_type: "web", contacts: [], logo_uri: "http://example.com/logo.png", client_uri: "http://example.com/client", policy_uri: "http://example.com/policy", tos_uri: "http://example.com/tos", - sector_identifier_uri: "http://example.com/uris", subject_type: "pairwise" + sector_identifier_uri: "http://example.com/uris", subject_type: "pairwise"} client_json = JSON.parse(response.body) expect(client_json["client_id"].length).to eq(32) expect(client_json["ppid"]).to eq(true) @@ -29,7 +29,7 @@ describe Api::OpenidConnect::ClientsController, type: :controller, suppress_csrf "User-Agent" => "Faraday v0.11.0" }) .to_return(status: 200, body: "[\"http://localhost\"]", headers: {}) - post :create, redirect_uris: ["http://localhost"], client_name: "diaspora client", + post :create, params: {redirect_uris: ["http://localhost"], client_name: "diaspora client", response_types: [], grant_types: [], application_type: "web", contacts: [], logo_uri: "http://example.com/logo.png", client_uri: "http://example.com/client", policy_uri: "http://example.com/policy", tos_uri: "http://example.com/tos", @@ -74,7 +74,7 @@ describe Api::OpenidConnect::ClientsController, type: :controller, suppress_csrf kid: "a3" } ] - } + }} client_json = JSON.parse(response.body) expect(client_json["client_id"].length).to eq(32) expect(client_json["ppid"]).to eq(true) @@ -98,13 +98,13 @@ describe Api::OpenidConnect::ClientsController, type: :controller, suppress_csrf }) .to_return(status: 200, body: "{\"keys\":[{\"kty\":\"RSA\",\"e\":\"AQAB\",\"n\":\"qpW\",\"use\":\"sig\"}]}", headers: {}) - post :create, redirect_uris: ["http://localhost"], client_name: "diaspora client", + post :create, params: {redirect_uris: ["http://localhost"], client_name: "diaspora client", response_types: [], grant_types: [], application_type: "web", contacts: [], logo_uri: "http://example.com/logo.png", client_uri: "http://example.com/client", policy_uri: "http://example.com/policy", tos_uri: "http://example.com/tos", sector_identifier_uri: "http://example.com/uris", subject_type: "pairwise", token_endpoint_auth_method: "private_key_jwt", - jwks_uri: "https://kentshikama.com/api/openid_connect/jwks.json" + jwks_uri: "https://kentshikama.com/api/openid_connect/jwks.json"} client_json = JSON.parse(response.body) expect(client_json["client_id"].length).to eq(32) expect(client_json["ppid"]).to eq(true) @@ -113,9 +113,9 @@ describe Api::OpenidConnect::ClientsController, type: :controller, suppress_csrf context "when redirect uri is missing" do it "should return a invalid_client_metadata error" do - post :create, response_types: [], grant_types: [], application_type: "web", contacts: [], + post :create, params: {response_types: [], grant_types: [], application_type: "web", contacts: [], logo_uri: "http://example.com/logo.png", client_uri: "http://example.com/client", - policy_uri: "http://example.com/policy", tos_uri: "http://example.com/tos" + policy_uri: "http://example.com/policy", tos_uri: "http://example.com/tos"} client_json = JSON.parse(response.body) expect(client_json["error"]).to have_content("invalid_client_metadata") end @@ -127,7 +127,7 @@ describe Api::OpenidConnect::ClientsController, type: :controller, suppress_csrf context "when an OIDC client already exists" do it "should return a client id" do - get :find, client_name: client.client_name + get :find, params: {client_name: client.client_name} client_id_json = JSON.parse(response.body) expect(client_id_json["client_id"]).to eq(client.client_id) end @@ -135,7 +135,7 @@ describe Api::OpenidConnect::ClientsController, type: :controller, suppress_csrf context "when an OIDC client doesn't already exist" do it "should return the appropriate error" do - get :find, client_name: "random_name" + get :find, params: {client_name: "random_name"} client_id_json = JSON.parse(response.body) expect(client_id_json["error"]).to eq("Client with name random_name does not exist") end diff --git a/spec/controllers/api/openid_connect/token_endpoint_controller_spec.rb b/spec/controllers/api/openid_connect/token_endpoint_controller_spec.rb index c3a484085cf1519e07780fd14b6bd7ee64b4676c..766a3c806bc8a84dfdd76dac48a9e06484ec2c6c 100644 --- a/spec/controllers/api/openid_connect/token_endpoint_controller_spec.rb +++ b/spec/controllers/api/openid_connect/token_endpoint_controller_spec.rb @@ -3,13 +3,14 @@ describe Api::OpenidConnect::TokenEndpointController, type: :controller, suppres describe "#create" do it "returns 200 on success" do - post :create, - grant_type: "authorization_code", - code: auth.create_code, - redirect_uri: auth.redirect_uri, - scope: auth.scopes.join(" "), - client_id: auth.o_auth_application.client_id, - client_secret: auth.o_auth_application.client_secret + post :create, params: { + grant_type: "authorization_code", + code: auth.create_code, + redirect_uri: auth.redirect_uri, + scope: auth.scopes.join(" "), + client_id: auth.o_auth_application.client_id, + client_secret: auth.o_auth_application.client_secret + } expect(response.code).to eq("200") end end diff --git a/spec/controllers/aspect_memberships_controller_spec.rb b/spec/controllers/aspect_memberships_controller_spec.rb index 2ff4066310b01fa4c684366b4f96e30b533ca74e..a577a613a8b1ed9f47e52c52fcf704223e5aeb18 100644 --- a/spec/controllers/aspect_memberships_controller_spec.rb +++ b/spec/controllers/aspect_memberships_controller_spec.rb @@ -22,13 +22,13 @@ describe AspectMembershipsController, type: :controller do end it "succeeds" do - post :create, format: :json, person_id: bob.person.id, aspect_id: @aspect1.id + post :create, params: {person_id: bob.person.id, aspect_id: @aspect1.id}, format: :json expect(response).to be_success end it "creates an aspect membership" do expect { - post :create, format: :json, person_id: bob.person.id, aspect_id: @aspect1.id + post :create, params: {person_id: bob.person.id, aspect_id: @aspect1.id}, format: :json }.to change { alice.contact_for(bob.person).aspect_memberships.count }.by(1) @@ -38,23 +38,23 @@ describe AspectMembershipsController, type: :controller do # argggg why? alice.contacts.reload expect { - post :create, format: :json, person_id: @person.id, aspect_id: @aspect0.id + post :create, params: {person_id: @person.id, aspect_id: @aspect0.id}, format: :json }.to change { alice.contacts.size }.by(1) end it "does not 500 on a duplicate key error" do - params = {format: :json, person_id: @person.id, aspect_id: @aspect0.id} - post :create, params - post :create, params + params = {person_id: @person.id, aspect_id: @aspect0.id} + post :create, params: params, format: :json + post :create, params: params, format: :json expect(response.status).to eq(400) expect(response.body).to eq(I18n.t("aspect_memberships.destroy.invalid_statement")) end context "json" do it "returns the aspect membership" do - post :create, format: :json, person_id: @person.id, aspect_id: @aspect0.id + post :create, params: {person_id: @person.id, aspect_id: @aspect0.id}, format: :json contact = @controller.current_user.contact_for(@person) expect(response.body).to eq(AspectMembershipPresenter.new(contact.aspect_memberships.first).base_hash.to_json) @@ -62,7 +62,7 @@ describe AspectMembershipsController, type: :controller do it "responds with an error message when the request failed" do expect(alice).to receive(:share_with).and_return(nil) - post :create, format: :json, person_id: @person.id, aspect_id: @aspect0.id + post :create, params: {person_id: @person.id, aspect_id: @aspect0.id}, format: :json expect(response.status).to eq(409) expect(response.body).to eq(I18n.t("aspects.add_to_aspect.failure")) end @@ -72,14 +72,14 @@ describe AspectMembershipsController, type: :controller do describe "#destroy" do it "removes contacts from an aspect" do membership = alice.add_contact_to_aspect(@contact, @aspect1) - delete :destroy, format: :json, id: membership.id + delete :destroy, params: {id: membership.id}, format: :json expect(response).to be_success @aspect1.reload expect(@aspect1.contacts.to_a).not_to include @contact end it "aspect membership does not exist" do - delete :destroy, format: :json, id: 123 + delete :destroy, params: {id: 123}, format: :json expect(response).not_to be_success expect(response.body).to eq(I18n.t("aspect_memberships.destroy.no_membership")) end diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 4278b078d761d522fa87b7b1c02a7d3fba583a1b..1f39d7312a6b4d25ba4a9ca0fef3a1d427cd8852 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -16,11 +16,11 @@ describe AspectsController, :type => :controller do describe "#show" do it "succeeds" do - get :show, 'id' => @alices_aspect_1.id.to_s + get :show, params: {id: @alices_aspect_1.id.to_s} expect(response).to be_redirect end it 'redirects on an invalid id' do - get :show, 'id' => 0 + get :show, params: {id: 0} expect(response).to be_redirect end end @@ -29,12 +29,12 @@ describe AspectsController, :type => :controller do context "with valid params" do it "creates an aspect" do expect(alice.aspects.count).to eq(2) - post :create, aspect: {name: "new aspect"} + post :create, params: {aspect: {name: "new aspect"}} expect(alice.reload.aspects.count).to eq(3) end it "returns the created aspect as json" do - post :create, aspect: {name: "new aspect"} + post :create, params: {aspect: {name: "new aspect"}} expect(JSON.parse(response.body)["id"]).to eq Aspect.find_by_name("new aspect").id expect(JSON.parse(response.body)["name"]).to eq "new aspect" end @@ -42,19 +42,19 @@ describe AspectsController, :type => :controller do context "with person_id param" do it "creates a contact if one does not already exist" do expect { - post :create, format: "js", person_id: eve.person.id, aspect: {name: "new"} + post :create, params: {person_id: eve.person.id, aspect: {name: "new"}}, format: :js }.to change { alice.contacts.count }.by(1) end it "adds a new contact to the new aspect" do - post :create, format: "js", person_id: eve.person.id, aspect: {name: "new"} + post :create, params: {person_id: eve.person.id, aspect: {name: "new"}}, format: :js expect(alice.aspects.find_by_name("new").contacts.count).to eq(1) end it "adds an existing contact to the new aspect" do - post :create, format: "js", person_id: bob.person.id, aspect: {name: "new"} + post :create, params: {person_id: bob.person.id, aspect: {name: "new"}}, format: :js expect(alice.aspects.find_by_name("new").contacts.count).to eq(1) end end @@ -63,12 +63,12 @@ describe AspectsController, :type => :controller do context "with invalid params" do it "does not create an aspect" do expect(alice.aspects.count).to eq(2) - post :create, aspect: {name: ""} + post :create, params: {aspect: {name: ""}} expect(alice.reload.aspects.count).to eq(2) end it "responds with 422" do - post :create, aspect: {name: ""} + post :create, params: {aspect: {name: ""}} expect(response.status).to eq(422) end end @@ -83,13 +83,13 @@ describe AspectsController, :type => :controller do new_user = FactoryGirl.create :user params = {"name" => "Bruisers"} params[:user_id] = new_user.id - put('update', :id => @alices_aspect_1.id, "aspect" => params) + put :update, params: {id: @alices_aspect_1.id, aspect: params} expect(Aspect.find(@alices_aspect_1.id).user_id).to eq(alice.id) end it "should return the name and id of the updated item" do params = {"name" => "Bruisers"} - put('update', :id => @alices_aspect_1.id, "aspect" => params) + put :update, params: {id: @alices_aspect_1.id, aspect: params} expect(response.body).to eq({ :id => @alices_aspect_1.id, :name => "Bruisers" }.to_json) end end @@ -100,7 +100,7 @@ describe AspectsController, :type => :controller do @alices_aspect_2.update_attributes(order_id: 20) ordered_aspect_ids = [@alices_aspect_2.id, @alices_aspect_1.id] - put(:update_order, ordered_aspect_ids: ordered_aspect_ids) + put :update_order, params: {ordered_aspect_ids: ordered_aspect_ids} expect(Aspect.find(@alices_aspect_1.id).order_id).to eq(1) expect(Aspect.find(@alices_aspect_2.id).order_id).to eq(0) @@ -115,12 +115,12 @@ describe AspectsController, :type => :controller do context "with no auto follow back aspect" do it "destoys the aspect" do expect(alice.aspects.to_a).to include @alices_aspect_1 - post :destroy, id: @alices_aspect_1.id + post :destroy, params: {id: @alices_aspect_1.id} expect(alice.reload.aspects.to_a).not_to include @alices_aspect_1 end it "renders a flash message on success" do - post :destroy, id: @alices_aspect_1.id + post :destroy, params: {id: @alices_aspect_1.id} expect(flash[:notice]).to eq(I18n.t("aspects.destroy.success", name: @alices_aspect_1.name)) expect(flash[:error]).to be_blank end @@ -135,20 +135,20 @@ describe AspectsController, :type => :controller do it "destoys the aspect" do expect(alice.aspects.to_a).to include @alices_aspect_1 - post :destroy, id: @alices_aspect_1.id + post :destroy, params: {id: @alices_aspect_1.id} expect(alice.reload.aspects.to_a).not_to include @alices_aspect_1 end it "disables auto follow back" do expect(alice.auto_follow_back).to be(true) expect(alice.auto_follow_back_aspect).to eq(@alices_aspect_1) - post :destroy, id: @alices_aspect_1.id + post :destroy, params: {id: @alices_aspect_1.id} expect(alice.auto_follow_back).to be(false) expect(alice.auto_follow_back_aspect).to eq(nil) end it "renders a flash message telling you to set a new auto follow back aspect" do - post :destroy, id: @alices_aspect_1.id + post :destroy, params: {id: @alices_aspect_1.id} expect(flash[:notice]).to eq(I18n.t("aspects.destroy.success_auto_follow_back", name: @alices_aspect_1.name)) expect(flash[:error]).to be_blank end @@ -160,7 +160,7 @@ describe AspectsController, :type => :controller do @alices_aspect_1.contacts_visible = false @alices_aspect_1.save - xhr :get, :toggle_contact_visibility, :aspect_id => @alices_aspect_1.id + get :toggle_contact_visibility, xhr: true, params: {aspect_id: @alices_aspect_1.id} expect(@alices_aspect_1.reload.contacts_visible).to be true end @@ -168,7 +168,7 @@ describe AspectsController, :type => :controller do @alices_aspect_1.contacts_visible = true @alices_aspect_1.save - xhr :get, :toggle_contact_visibility, :aspect_id => @alices_aspect_1.id + get :toggle_contact_visibility, xhr: true, params: {aspect_id: @alices_aspect_1.id} expect(@alices_aspect_1.reload.contacts_visible).to be false end end diff --git a/spec/controllers/blocks_controller_spec.rb b/spec/controllers/blocks_controller_spec.rb index 3bf98930c72571e2c8e4987f2f8bffca7d6fd782..93970e8926e5b5cc7d208e58704a3a6cba509736 100644 --- a/spec/controllers/blocks_controller_spec.rb +++ b/spec/controllers/blocks_controller_spec.rb @@ -6,18 +6,18 @@ describe BlocksController, :type => :controller do describe "#create" do it "creates a block" do expect { - post :create, format: :json, block: {person_id: eve.person.id} + post :create, params: {block: {person_id: eve.person.id}}, format: :json }.to change { alice.blocks.count }.by(1) end it "responds with 204" do - post :create, format: :json, block: {person_id: eve.person.id} + post :create, params: {block: {person_id: eve.person.id}}, format: :json expect(response.status).to eq(204) end it "calls #disconnect_if_contact" do expect(@controller).to receive(:disconnect_if_contact).with(bob.person) - post :create, format: :json, block: {person_id: bob.person.id} + post :create, params: {block: {person_id: bob.person.id}}, format: :json end end @@ -27,13 +27,13 @@ describe BlocksController, :type => :controller do end it "responds with 204" do - delete :destroy, format: :json, id: @block.id + delete :destroy, params: {id: @block.id}, format: :json expect(response.status).to eq(204) end it "removes a block" do expect { - delete :destroy, format: :json, id: @block.id + delete :destroy, params: {id: @block.id}, format: :json }.to change { alice.blocks.count }.by(-1) end end diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index a155cf531b230c31e4f878f0cf08c750d91771a8..4b9e22ce5a6011c3efae97b15a2a1f0df0132771 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -21,13 +21,13 @@ describe CommentsController, :type => :controller do end it 'responds to format json' do - post :create, comment_hash.merge(:format => 'json') + post :create, params: comment_hash, format: :json expect(response.code).to eq('201') expect(response.body).to match comment_hash[:text] end it 'responds to format mobile' do - post :create, comment_hash.merge(:format => 'mobile') + post :create, params: comment_hash, format: :mobile expect(response).to be_success end end @@ -39,21 +39,21 @@ describe CommentsController, :type => :controller do end it 'comments' do - post :create, comment_hash + post :create, params: comment_hash expect(response.code).to eq('201') end it "doesn't overwrite author_id" do new_user = FactoryGirl.create(:user) comment_hash[:author_id] = new_user.person.id.to_s - post :create, comment_hash + post :create, params: comment_hash expect(Comment.find_by_text(comment_hash[:text]).author_id).to eq(alice.person.id) end it "doesn't overwrite id" do old_comment = alice.comment!(@post, "hello") comment_hash[:id] = old_comment.id - post :create, comment_hash + post :create, params: comment_hash expect(old_comment.reload.text).to eq('hello') end end @@ -63,7 +63,7 @@ describe CommentsController, :type => :controller do @post = eve.post :status_message, :text => 'GIANTS', :to => aspect_to_post expect(alice).not_to receive(:comment) - post :create, comment_hash + post :create, params: comment_hash expect(response.code).to eq("404") expect(response.body).to eq(I18n.t("comments.create.error")) end @@ -85,7 +85,7 @@ describe CommentsController, :type => :controller do comment = bob.comment!(@message, "hey") expect(bob).to receive(:retract).with(comment) - delete :destroy, :format => "js", :post_id => 1, :id => comment.id + delete :destroy, params: {post_id: 1, id: comment.id}, format: :js expect(response.status).to eq(204) end @@ -93,7 +93,7 @@ describe CommentsController, :type => :controller do comment = alice.comment!(@message, "hey") expect(bob).to receive(:retract).with(comment) - delete :destroy, :format => "js", :post_id => 1, :id => comment.id + delete :destroy, params: {post_id: 1, id: comment.id}, format: :js expect(response.status).to eq(204) end end @@ -103,7 +103,7 @@ describe CommentsController, :type => :controller do comment = alice.comment!(@message, "hey") expect(alice).to receive(:retract).with(comment) - delete :destroy, :format => "js", :post_id => 1, :id => comment.id + delete :destroy, params: {post_id: 1, id: comment.id}, format: :js expect(response.status).to eq(204) end @@ -112,13 +112,13 @@ describe CommentsController, :type => :controller do comment2 = eve.comment!(@message, "hey") expect(alice).not_to receive(:retract).with(comment1) - delete :destroy, :format => "js", :post_id => 1, :id => comment2.id + delete :destroy, params: {post_id: 1, id: comment2.id}, format: :js expect(response.status).to eq(403) end end it 'renders nothing and 404 on a nonexistent comment' do - delete :destroy, :post_id => 1, :id => 343415 + delete :destroy, params: {post_id: 1, id: 343_415} expect(response.status).to eq(404) expect(response.body.strip).to be_empty end @@ -131,19 +131,19 @@ describe CommentsController, :type => :controller do end it 'works for mobile' do - get :index, :post_id => @message.id, :format => 'mobile' + get :index, params: {post_id: @message.id}, format: :mobile expect(response).to be_success end it 'returns all the comments for a post' do comments = [alice, bob, eve].map{ |u| u.comment!(@message, "hey") } - get :index, :post_id => @message.id, :format => :json + get :index, params: {post_id: @message.id}, format: :json expect(JSON.parse(response.body).map {|comment| comment["id"] }).to match_array(comments.map(&:id)) end it 'returns a 404 on a nonexistent post' do - get :index, :post_id => 235236, :format => :json + get :index, params: {post_id: 235_236}, format: :json expect(response.status).to eq(404) end @@ -151,7 +151,7 @@ describe CommentsController, :type => :controller do aspect_to_post = eve.aspects.where(:name => "generic").first message = eve.post(:status_message, :text => "hey", :to => aspect_to_post.id) bob.comment!(@message, "hey") - get :index, :post_id => message.id, :format => :json + get :index, params: {post_id: message.id}, format: :json expect(response.status).to eq(404) end end diff --git a/spec/controllers/contacts_controller_spec.rb b/spec/controllers/contacts_controller_spec.rb index e12a97c3fdce33514e82b731039a23c8a4e61769..c50243264a0179c19f32e5abca72cea645e5642a 100644 --- a/spec/controllers/contacts_controller_spec.rb +++ b/spec/controllers/contacts_controller_spec.rb @@ -11,7 +11,7 @@ describe ContactsController, :type => :controller do describe '#index' do context 'format mobile' do it "succeeds" do - get :index, :format => 'mobile' + get :index, format: :mobile expect(response).to be_success end end @@ -40,26 +40,26 @@ describe ContactsController, :type => :controller do end it "succeeds" do - get :index, q: @person1.first_name, format: "json" + get :index, params: {q: @person1.first_name}, format: :json expect(response).to be_success end it "responds with json" do - get :index, q: @person1.first_name, format: "json" + get :index, params: {q: @person1.first_name}, format: :json expect(response.body).to eq([@person1].to_json) end it "only returns contacts" do - get :index, q: @person2.first_name, format: "json" + get :index, params: {q: @person2.first_name}, format: :json expect(response.body).to eq([].to_json) end it "only returns mutual contacts when mutual parameter is true" do - get :index, q: @person1.first_name, mutual: true, format: "json" + get :index, params: {q: @person1.first_name, mutual: true}, format: :json expect(response.body).to eq([].to_json) - get :index, q: @person2.first_name, mutual: true, format: "json" + get :index, params: {q: @person2.first_name, mutual: true}, format: :json expect(response.body).to eq([].to_json) - get :index, q: @person3.first_name, mutual: true, format: "json" + get :index, params: {q: @person3.first_name, mutual: true}, format: :json expect(response.body).to eq([@person3].to_json) end end @@ -67,7 +67,7 @@ describe ContactsController, :type => :controller do context "for pagination on the contacts page" do context "without parameters" do it "returns contacts" do - get :index, format: "json", page: "1" + get :index, params: {page: "1"}, format: :json contact_ids = JSON.parse(response.body).map {|c| c["id"] } expect(contact_ids.to_set).to eq(bob.contacts.map(&:id).to_set) end @@ -76,7 +76,7 @@ describe ContactsController, :type => :controller do contact = bob.contacts.first contact.update_attributes(receiving: false) - get :index, format: "json", page: "1" + get :index, params: {params: {page: "1"}}, format: :json contact_ids = JSON.parse(response.body).map {|c| c["id"] } expect(contact_ids.to_set).to eq(bob.contacts.receiving.map(&:id).to_set) expect(contact_ids).not_to include(contact.id) @@ -90,13 +90,13 @@ describe ContactsController, :type => :controller do end it "returns all contacts (sharing and receiving)" do - get :index, format: "json", page: "1", set: "all" + get :index, params: {page: "1", set: "all"}, format: :json contact_ids = JSON.parse(response.body).map {|c| c["id"] } expect(contact_ids.to_set).to eq(bob.contacts.map(&:id).to_set) end it "sorts contacts by receiving status" do - get :index, format: "json", page: "1", set: "all" + get :index, params: {page: "1", set: "all"}, format: :json contact_ids = JSON.parse(response.body).map {|c| c["id"] } expect(contact_ids).to eq(bob.contacts.order("receiving DESC").map(&:id)) expect(contact_ids.last).to eq(bob.contacts.first.id) @@ -111,16 +111,16 @@ describe ContactsController, :type => :controller do end it "returns all contacts" do - get :index, format: "json", a_id: @aspect.id, page: "1" + get :index, params: {a_id: @aspect.id, page: "1"}, format: :json contact_ids = JSON.parse(response.body).map {|c| c["id"] } expect(contact_ids.to_set).to eq(bob.contacts.map(&:id).to_set) end it "sorts contacts by aspect memberships" do - get :index, format: "json", a_id: @aspect.id, page: "1" + get :index, params: {a_id: @aspect.id, page: "1"}, format: :json expect(JSON.parse(response.body).first["person"]["id"]).to eq(@person.id) - get :index, format: "json", a_id: bob.aspects.first.id, page: "1" + get :index, params: {a_id: bob.aspects.first.id, page: "1"}, format: :json expect(JSON.parse(response.body).first["person"]["id"]).not_to eq(@person.id) end end diff --git a/spec/controllers/conversation_visibilities_controller_spec.rb b/spec/controllers/conversation_visibilities_controller_spec.rb index 5b8893c1ec8afaec1ca76ca4b0df9307830eef16..973873e48b7df2eeccf48fc82d6305cad04991cf 100644 --- a/spec/controllers/conversation_visibilities_controller_spec.rb +++ b/spec/controllers/conversation_visibilities_controller_spec.rb @@ -19,7 +19,7 @@ describe ConversationVisibilitiesController, :type => :controller do describe '#destroy' do it 'deletes the visibility' do expect { - delete :destroy, :conversation_id => @conversation.id + delete :destroy, params: {conversation_id: @conversation.id} }.to change(ConversationVisibility, :count).by(-1) end @@ -28,20 +28,20 @@ describe ConversationVisibilitiesController, :type => :controller do sign_in user2, scope: :user expect { - delete :destroy, :conversation_id => @conversation.id + delete :destroy, params: {conversation_id: @conversation.id} }.not_to change(ConversationVisibility, :count) end it 'returns "hidden"' do - get :destroy, :conversation_id => @conversation.id + get :destroy, params: {conversation_id: @conversation.id} expect(flash.notice).to include("hidden") end it 'returns "deleted" when last participant' do - get :destroy, :conversation_id => @conversation.id + get :destroy, params: {conversation_id: @conversation.id} sign_out :user sign_in bob, scope: :user - get :destroy, :conversation_id => @conversation.id + get :destroy, params: {conversation_id: @conversation.id} expect(flash.notice).to include("deleted") end end diff --git a/spec/controllers/conversations_controller_spec.rb b/spec/controllers/conversations_controller_spec.rb index 9bf0c6cc19bf1dfd37bbe1c6d86009a03e50450e..dd6b646778a1dc0ac366e122b5a8c1620221df36 100644 --- a/spec/controllers/conversations_controller_spec.rb +++ b/spec/controllers/conversations_controller_spec.rb @@ -17,17 +17,17 @@ describe ConversationsController, :type => :controller do describe "#new modal" do context "desktop" do it "succeeds" do - get :new, modal: true + get :new, params: {modal: true} expect(response).to be_success end it "assigns a contact if passed a contact id" do - get :new, contact_id: alice.contacts.first.id, modal: true + get :new, params: {contact_id: alice.contacts.first.id, modal: true} expect(controller.gon.conversation_prefill).to eq([alice.contacts.first.person.as_json]) end it "assigns a set of contacts if passed an aspect id" do - get :new, aspect_id: alice.aspects.first.id, modal: true + get :new, params: {aspect_id: alice.aspects.first.id, modal: true} expect(controller.gon.conversation_prefill).to eq(alice.aspects.first.contacts.map {|c| c.person.as_json }) end end @@ -40,7 +40,7 @@ describe ConversationsController, :type => :controller do it "assigns a json list of contacts that are sharing with the person" do sharing_user = FactoryGirl.create(:user_with_aspect) sharing_user.share_with(alice.person, sharing_user.aspects.first) - get :new, modal: true + get :new, params: {modal: true} expect(assigns(:contacts_json)) .to include(alice.contacts.where(sharing: true, receiving: true).first.person.name) alice.contacts << Contact.new(person_id: eve.person.id, user_id: alice.id, sharing: false, receiving: true) @@ -51,7 +51,7 @@ describe ConversationsController, :type => :controller do it "does not allow XSS via the name parameter" do ["</script><script>alert(1);</script>", '"}]});alert(1);(function f() {var foo = [{b:"'].each do |xss| - get :new, modal: true, name: xss + get :new, params: {modal: true, name: xss} expect(response.body).not_to include xss end end @@ -60,7 +60,7 @@ describe ConversationsController, :type => :controller do xss = "<script>alert(0);</script>" contact = alice.contacts.first contact.person.profile.update_attribute(:first_name, xss) - get :new, modal: true + get :new, params: {modal: true} json = JSON.parse(assigns(:contacts_json)).first expect(json["value"].to_s).to eq(contact.id.to_s) expect(json["name"]).to_not include(xss) @@ -101,7 +101,7 @@ describe ConversationsController, :type => :controller do end it "retrieves a conversation" do - get :index, conversation_id: @conversations.first.id + get :index, params: {conversation_id: @conversations.first.id} expect(response).to be_success expect(assigns[:visibilities]).to match_array(@visibilities) expect(assigns[:conversation]).to eq(@conversations.first) @@ -109,7 +109,7 @@ describe ConversationsController, :type => :controller do it "does not let you access conversations where you are not a recipient" do sign_in eve, scope: :user - get :index, conversation_id: @conversations.first.id + get :index, params: {conversation_id: @conversations.first.id} expect(assigns[:conversation]).to be_nil end @@ -125,31 +125,30 @@ describe ConversationsController, :type => :controller do describe "#create" do context "desktop" do context "with a valid conversation" do - before do - @hash = { - format: :js, + let(:params) { + { conversation: {subject: "secret stuff", text: "text debug"}, person_ids: alice.contacts.first.person.id.to_s } - end + } it "creates a conversation" do - expect { post :create, @hash }.to change(Conversation, :count).by(1) + expect { post :create, params: params, format: :js }.to change(Conversation, :count).by(1) end it "creates a message" do - expect { post :create, @hash }.to change(Message, :count).by(1) + expect { post :create, params: params, format: :js }.to change(Message, :count).by(1) end it "responds with the conversation id as JSON" do - post :create, @hash + post :create, params: params, format: :js expect(response).to be_success expect(JSON.parse(response.body)["id"]).to eq(Conversation.first.id) end it "sets the author to the current_user" do - @hash[:author] = FactoryGirl.create(:user) - post :create, @hash + params[:author] = FactoryGirl.create(:user) + post :create, params: params, format: :js expect(Message.first.author).to eq(alice.person) expect(Conversation.first.author).to eq(alice.person) end @@ -159,130 +158,128 @@ describe ConversationsController, :type => :controller do subject: "not spam", messages_attributes: [{author: alice.person, text: "cool stuff"}]) expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch) - post :create, @hash + post :create, params: params, format: :js end end context "with empty subject" do - before do - @hash = { - format: :js, + let(:params) { + { conversation: {subject: " ", text: "text debug"}, person_ids: alice.contacts.first.person.id.to_s } - end + } it "creates a conversation" do - expect { post :create, @hash }.to change(Conversation, :count).by(1) + expect { post :create, params: params, format: :js }.to change(Conversation, :count).by(1) end it "creates a message" do - expect { post :create, @hash }.to change(Message, :count).by(1) + expect { post :create, params: params, format: :js }.to change(Message, :count).by(1) end it "responds with the conversation id as JSON" do - post :create, @hash + post :create, params: params, format: :js expect(response).to be_success expect(JSON.parse(response.body)["id"]).to eq(Conversation.first.id) end end context "with empty text" do - before do - @hash = { - format: :js, + let(:params) { + { conversation: {subject: "secret stuff", text: " "}, person_ids: alice.contacts.first.person.id.to_s } - end + } it "does not create a conversation" do - expect { post :create, @hash }.not_to change(Conversation, :count) + expect { post :create, params: params, format: :js }.not_to change(Conversation, :count) end it "does not create a message" do - expect { post :create, @hash }.not_to change(Message, :count) + expect { post :create, params: params, format: :js }.not_to change(Message, :count) end it "responds with an error message" do - post :create, @hash + post :create, params: params, format: :js expect(response).not_to be_success expect(response.body).to eq(I18n.t("conversations.create.fail")) end end context "with empty contact" do - before do - @hash = { - format: :js, + let(:params) { + { conversation: {subject: "secret stuff", text: "text debug"}, person_ids: " " } - end + } it "does not create a conversation" do - expect { post :create, @hash }.not_to change(Conversation, :count) + expect { post :create, params: params, format: :js }.not_to change(Conversation, :count) end it "does not create a message" do - expect { post :create, @hash }.not_to change(Message, :count) + expect { post :create, params: params, format: :js }.not_to change(Message, :count) end it "responds with an error message" do - post :create, @hash + post :create, params: params, format: :js expect(response).not_to be_success expect(response.body).to eq(I18n.t("javascripts.conversation.create.no_recipient")) end end context "with nil contact" do - before do - @hash = { - format: :js, + let(:params) { + { conversation: {subject: "secret stuff", text: "text debug"}, person_ids: nil } - end + } it "does not create a conversation" do - expect { post :create, @hash }.not_to change(Conversation, :count) + expect { post :create, params: params, format: :js }.not_to change(Conversation, :count) end it "does not create a message" do - expect { post :create, @hash }.not_to change(Message, :count) + expect { post :create, params: params, format: :js }.not_to change(Message, :count) end it "responds with an error message" do - post :create, @hash + post :create, params: params, format: :js expect(response).not_to be_success expect(response.body).to eq(I18n.t("javascripts.conversation.create.no_recipient")) end end context "with non-mutual contact" do - before do - @person1 = FactoryGirl.create(:person) - @person2 = FactoryGirl.create(:person) - alice.contacts.create!(receiving: false, sharing: true, person: @person2) - @person3 = FactoryGirl.create(:person) - alice.contacts.create!(receiving: true, sharing: false, person: @person3) - @hash = { - format: :js, + let(:person1) { FactoryGirl.create(:person) } + let(:person2) { FactoryGirl.create(:person) } + let(:person3) { FactoryGirl.create(:person) } + let(:params) { + { conversation: {subject: "secret stuff", text: "text debug"}, - person_ids: [@person1.id, @person2.id, @person3.id].join(",") + person_ids: [person1.id, person2.id, person3.id].join(",") } + } + + before do + alice.contacts.create!(receiving: false, sharing: true, person: person2) + alice.contacts.create!(receiving: true, sharing: false, person: person3) end it "does not create a conversation" do - expect { post :create, @hash }.not_to change(Conversation, :count) + expect { post :create, params: params, format: :js }.not_to change(Conversation, :count) end it "does not create a message" do - expect { post :create, @hash }.not_to change(Message, :count) + expect { post :create, params: params, format: :js }.not_to change(Message, :count) end it "responds with an error message" do - post :create, @hash + post :create, params: params, format: :js expect(response).not_to be_success expect(response.body).to eq(I18n.t("javascripts.conversation.create.no_recipient")) end @@ -295,31 +292,30 @@ describe ConversationsController, :type => :controller do end context "with a valid conversation" do - before do - @hash = { - format: :js, + let(:params) { + { conversation: {subject: "secret stuff", text: "text debug"}, contact_ids: alice.contacts.first.id.to_s } - end + } it "creates a conversation" do - expect { post :create, @hash }.to change(Conversation, :count).by(1) + expect { post :create, params: params, format: :js }.to change(Conversation, :count).by(1) end it "creates a message" do - expect { post :create, @hash }.to change(Message, :count).by(1) + expect { post :create, params: params, format: :js }.to change(Message, :count).by(1) end it "responds with the conversation id as JSON" do - post :create, @hash + post :create, params: params, format: :js expect(response).to be_success expect(JSON.parse(response.body)["id"]).to eq(Conversation.first.id) end it "sets the author to the current_user" do - @hash[:author] = FactoryGirl.create(:user) - post :create, @hash + params[:author] = FactoryGirl.create(:user) + post :create, params: params, format: :js expect(Message.first.author).to eq(alice.person) expect(Conversation.first.author).to eq(alice.person) end @@ -329,127 +325,122 @@ describe ConversationsController, :type => :controller do subject: "not spam", messages_attributes: [{author: alice.person, text: "cool stuff"}]) expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch) - post :create, @hash + post :create, params: params, format: :js end end context "with empty subject" do - before do - @hash = { - format: :js, + let(:params) { + { conversation: {subject: " ", text: "text debug"}, contact_ids: alice.contacts.first.id.to_s } - end + } it "creates a conversation" do - expect { post :create, @hash }.to change(Conversation, :count).by(1) + expect { post :create, params: params, format: :js }.to change(Conversation, :count).by(1) end it "creates a message" do - expect { post :create, @hash }.to change(Message, :count).by(1) + expect { post :create, params: params, format: :js }.to change(Message, :count).by(1) end it "responds with the conversation id as JSON" do - post :create, @hash + post :create, params: params, format: :js expect(response).to be_success expect(JSON.parse(response.body)["id"]).to eq(Conversation.first.id) end end context "with empty text" do - before do - @hash = { - format: :js, + let(:params) { + { conversation: {subject: "secret stuff", text: " "}, contact_ids: alice.contacts.first.id.to_s } - end + } it "does not create a conversation" do - expect { post :create, @hash }.not_to change(Conversation, :count) + expect { post :create, params: params, format: :js }.not_to change(Conversation, :count) end it "does not create a message" do - expect { post :create, @hash }.not_to change(Message, :count) + expect { post :create, params: params, format: :js }.not_to change(Message, :count) end it "responds with an error message" do - post :create, @hash + post :create, params: params, format: :js expect(response).not_to be_success expect(response.body).to eq(I18n.t("conversations.create.fail")) end end context "with empty contact" do - before do - @hash = { - format: :js, + let(:params) { + { conversation: {subject: "secret stuff", text: "text debug"}, contact_ids: " " } - end + } it "does not create a conversation" do - expect { post :create, @hash }.not_to change(Conversation, :count) + expect { post :create, params: params, format: :js }.not_to change(Conversation, :count) end it "does not create a message" do - expect { post :create, @hash }.not_to change(Message, :count) + expect { post :create, params: params, format: :js }.not_to change(Message, :count) end it "responds with an error message" do - post :create, @hash + post :create, params: params, format: :js expect(response).not_to be_success expect(response.body).to eq(I18n.t("javascripts.conversation.create.no_recipient")) end end context "with nil contact" do - before do - @hash = { - format: :js, + let(:params) { + { conversation: {subject: "secret stuff", text: "text debug"}, contact_ids: nil } - end + } it "does not create a conversation" do - expect { post :create, @hash }.not_to change(Conversation, :count) + expect { post :create, params: params, format: :js }.not_to change(Conversation, :count) end it "does not create a message" do - expect { post :create, @hash }.not_to change(Message, :count) + expect { post :create, params: params, format: :js }.not_to change(Message, :count) end it "responds with an error message" do - post :create, @hash + post :create, params: params, format: :js expect(response).not_to be_success expect(response.body).to eq(I18n.t("javascripts.conversation.create.no_recipient")) end end context "with non-mutual contact" do - before do - @contact1 = alice.contacts.create(receiving: false, sharing: true, person: FactoryGirl.create(:person)) - @contact2 = alice.contacts.create(receiving: true, sharing: false, person: FactoryGirl.create(:person)) - @hash = { - format: :js, + let(:contact1) { alice.contacts.create(receiving: false, sharing: true, person: FactoryGirl.create(:person)) } + let(:contact2) { alice.contacts.create(receiving: true, sharing: false, person: FactoryGirl.create(:person)) } + let(:params) { + { conversation: {subject: "secret stuff", text: "text debug"}, - person_ids: [@contact1.id, @contact2.id].join(",") + contact_ids: [contact1.id, contact2.id].join(",") } - end + } it "does not create a conversation" do - expect { post :create, @hash }.not_to change(Conversation, :count) + expect { post :create, params: params, format: :js }.not_to change(Conversation, :count) end it "does not create a message" do - expect { post :create, @hash }.not_to change(Message, :count) + expect { post :create, params: params, format: :js }.not_to change(Message, :count) end it "responds with an error message" do - post :create, @hash + post :create, params: params, format: :js expect(response).not_to be_success expect(response.body).to eq(I18n.t("javascripts.conversation.create.no_recipient")) end @@ -458,47 +449,45 @@ describe ConversationsController, :type => :controller do end describe "#show" do - before do - hash = { + let(:conversation) { + Conversation.create( author: alice.person, participant_ids: [alice.contacts.first.person.id, alice.person.id], subject: "not spam", messages_attributes: [{author: alice.person, text: "cool stuff"}] - } - @conversation = Conversation.create(hash) - end + ) + } it "succeeds with json" do - get :show, :id => @conversation.id, :format => :json + get :show, params: {id: conversation.id}, format: :json expect(response).to be_success - expect(assigns[:conversation]).to eq(@conversation) - expect(response.body).to include @conversation.guid + expect(assigns[:conversation]).to eq(conversation) + expect(response.body).to include conversation.guid end it "redirects to index" do - get :show, :id => @conversation.id - expect(response).to redirect_to(conversations_path(:conversation_id => @conversation.id)) + get :show, params: {id: conversation.id} + expect(response).to redirect_to(conversations_path(conversation_id: conversation.id)) end end describe "#raw" do - before do - hash = { + let(:conversation) { + Conversation.create( author: alice.person, participant_ids: [alice.contacts.first.person.id, alice.person.id], subject: "not spam", messages_attributes: [{author: alice.person, text: "cool stuff"}] - } - @conversation = Conversation.create(hash) - end + ) + } it "returns html of conversation" do - get :raw, conversation_id: @conversation.id - expect(response).to render_template(partial: "show", locals: {conversation: @conversation}) + get :raw, params: {conversation_id: conversation.id} + expect(response).to render_template(partial: "show", locals: {conversation: conversation}) end it "returns 404 when requesting non-existant conversation" do - get :raw, conversation_id: -1 + get :raw, params: {conversation_id: -1} expect(response).to have_http_status(404) end end diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index 80b9bc0234641dcf3c7b0ef625b7877e703865c4..2e5a9b3a8280b3a77720b06465360f265e3d8a72 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -40,7 +40,7 @@ describe HomeController, type: :controller do it "redirects to the stream if the user is signed in" do sign_in alice - get :show, home: true + get :show expect(response).to redirect_to(stream_path) end end diff --git a/spec/controllers/invitation_codes_controller_spec.rb b/spec/controllers/invitation_codes_controller_spec.rb index 90864fefc090db3a2fa12522f04be3ded5901a62..afc317f99253196d23b32d0f6f2405d830dbd12d 100644 --- a/spec/controllers/invitation_codes_controller_spec.rb +++ b/spec/controllers/invitation_codes_controller_spec.rb @@ -1,7 +1,7 @@ describe InvitationCodesController, type: :controller do describe "#show" do it "redirects to the root page if the invitation code is invalid" do - get :show, id: "InvalidInvitationCode" + get :show, params: {id: "InvalidInvitationCode"} expect(response).to redirect_to root_path expect(flash[:notice]).to eq(I18n.t("invitation_codes.not_valid")) end @@ -10,13 +10,13 @@ describe InvitationCodesController, type: :controller do let(:invitation_token) { alice.invitation_code.token } it "redirects logged out users to the sign in page" do - post :show, id: invitation_token + post :show, params: {id: invitation_token} expect(response).to redirect_to new_user_registration_path(invite: {token: invitation_token}) end it "redirects logged in users the the inviters page" do sign_in bob - post :show, id: invitation_token + post :show, params: {id: invitation_token} expect(response).to redirect_to person_path(alice.person) expect(flash[:notice]).to eq(I18n.t("invitation_codes.already_logged_in", inviter: alice.name)) end diff --git a/spec/controllers/invitations_controller_spec.rb b/spec/controllers/invitations_controller_spec.rb index 7fb2b03fb35a3f45b94785a74712e451ff0297e8..9ca17c1255cfb2c1fa3215ec0334f49f9fbd3a3d 100644 --- a/spec/controllers/invitations_controller_spec.rb +++ b/spec/controllers/invitations_controller_spec.rb @@ -17,16 +17,16 @@ describe InvitationsController, type: :controller do it "does not create an EmailInviter" do expect(Workers::Mail::InviteEmail).not_to receive(:perform_async) - post :create, invite_params + post :create, params: invite_params end it "returns to the previous page" do - post :create, invite_params + post :create, params: invite_params expect(response).to redirect_to referer end it "flashes an error" do - post :create, invite_params + post :create, params: invite_params expect(flash[:error]).to eq(I18n.t("invitations.create.empty")) end end @@ -39,16 +39,16 @@ describe InvitationsController, type: :controller do expect(Workers::Mail::InviteEmail).to receive(:perform_async).with( emails, alice.id, invite_params[:email_inviter] ) - post :create, invite_params + post :create, params: invite_params end it "returns to the previous page on success" do - post :create, invite_params + post :create, params: invite_params expect(response).to redirect_to referer end it "flashes a notice" do - post :create, invite_params + post :create, params: invite_params expected = I18n.t("invitations.create.sent", emails: emails) expect(flash[:notice]).to eq(expected) end @@ -60,16 +60,16 @@ describe InvitationsController, type: :controller do it "does not create an InviteEmail worker" do expect(Workers::Mail::InviteEmail).not_to receive(:perform_async) - post :create, invite_params + post :create, params: invite_params end it "returns to the previous page" do - post :create, invite_params + post :create, params: invite_params expect(response).to redirect_to referer end it "flashes an error" do - post :create, invite_params + post :create, params: invite_params expected = I18n.t("invitations.create.rejected", emails: emails) expect(flash[:error]).to eq(expected) @@ -85,16 +85,16 @@ describe InvitationsController, type: :controller do expect(Workers::Mail::InviteEmail).to receive(:perform_async).with( valid_emails, alice.id, invite_params[:email_inviter] ) - post :create, invite_params + post :create, params: invite_params end it "returns to the previous page" do - post :create, invite_params + post :create, params: invite_params expect(response).to redirect_to referer end it "flashes a notice" do - post :create, invite_params + post :create, params: invite_params expected = I18n.t("invitations.create.sent", emails: valid_emails.split(",").join(", ")) + ". " + I18n.t("invitations.create.rejected", emails: invalid_emails) expect(flash[:error]).to eq(expected) @@ -109,7 +109,7 @@ describe InvitationsController, type: :controller do it "displays an error if invitations are closed" do AppConfig.settings.invitations.open = false - post :create, invite_params + post :create, params: invite_params expect(flash[:error]).to eq(I18n.t("invitations.create.closed")) end @@ -117,7 +117,7 @@ describe InvitationsController, type: :controller do it "displays an error when no invitations are left" do alice.invitation_code.update_attributes(count: 0) - post :create, invite_params + post :create, params: invite_params expect(flash[:error]).to eq(I18n.t("invitations.create.no_more")) end @@ -127,7 +127,7 @@ describe InvitationsController, type: :controller do AppConfig.settings.invitations.open = false alice.invitation_code.update_attributes(count: 0) - post :create, invite_params + post :create, params: invite_params expect(flash[:error]).to be_nil end diff --git a/spec/controllers/jasmine_fixtures/aspects_spec.rb b/spec/controllers/jasmine_fixtures/aspects_spec.rb index e2adf493dd6c27f81d0f0c2f713e9d42e76f7a61..b82fbc2de0c1c8a3eebbd1a159d5c38081534a3b 100644 --- a/spec/controllers/jasmine_fixtures/aspects_spec.rb +++ b/spec/controllers/jasmine_fixtures/aspects_spec.rb @@ -22,14 +22,14 @@ describe StreamsController, :type => :controller do end it "generates a jasmine fixture with a prefill", :fixture => true do - get :aspects, :prefill => "reshare things" + get :aspects, params: {prefill: "reshare things"} save_fixture(html_for("body"), "aspects_index_prefill") end it 'generates a jasmine fixture with services', :fixture => true do alice.services << Services::Facebook.create(:user_id => alice.id) alice.services << Services::Twitter.create(:user_id => alice.id) - get :aspects, :prefill => "reshare things" + get :aspects, params: {prefill: "reshare things"} save_fixture(html_for("body"), "aspects_index_services") end @@ -44,7 +44,7 @@ describe StreamsController, :type => :controller do it 'generates a jasmine fixture with only posts', :fixture => true do 2.times { bob.post(:status_message, :text => "Is anyone out there?", :to => @bob.aspects.where(:name => "generic").first.id) } - get :aspects, :only_posts => true + get :aspects, params: {only_posts: true} save_fixture(response.body, "aspects_index_only_posts") end diff --git a/spec/controllers/jasmine_fixtures/contacts_spec.rb b/spec/controllers/jasmine_fixtures/contacts_spec.rb index 127f9be2a77bd4b437ec02a44017288ee9faf0a4..06262aed2830286af4a36fb15f64caa7a7977bce 100644 --- a/spec/controllers/jasmine_fixtures/contacts_spec.rb +++ b/spec/controllers/jasmine_fixtures/contacts_spec.rb @@ -13,12 +13,12 @@ describe ContactsController, :type => :controller do end it "generates the aspects_manage fixture", :fixture => true do - get :index, :a_id => @aspect.id + get :index, params: {a_id: @aspect.id} save_fixture(html_for("body"), "aspects_manage") end it "generates the aspects_manage_contacts_json fixture", fixture: true do - get :index, format: :json, a_id: @aspect.id, page: "1" + get :index, params: {a_id: @aspect.id, page: "1"}, format: :json save_fixture(response.body, "aspects_manage_contacts_json") end diff --git a/spec/controllers/jasmine_fixtures/conversations_spec.rb b/spec/controllers/jasmine_fixtures/conversations_spec.rb index cfba3708ba47a7c6fce4217bc8741dd314e9f0c4..a35993c0b538d30b320001318db19d8a4c047ebf 100644 --- a/spec/controllers/jasmine_fixtures/conversations_spec.rb +++ b/spec/controllers/jasmine_fixtures/conversations_spec.rb @@ -22,10 +22,10 @@ describe ConversationsController, :type => :controller do end it "generates a jasmine fixture", :fixture => true do - get :index, :conversation_id => @conv1.id + get :index, params: {conversation_id: @conv1.id} save_fixture(html_for("body"), "conversations_unread") - get :index, :conversation_id => @conv1.id + get :index, params: {conversation_id: @conv1.id} save_fixture(html_for("body"), "conversations_read") end end diff --git a/spec/controllers/jasmine_fixtures/people_spec.rb b/spec/controllers/jasmine_fixtures/people_spec.rb index 432ff5d5c698208cfc112e2884fbf62108e01b58..77ec784248837ec19cff6369e58ee2c87dc1ee2a 100644 --- a/spec/controllers/jasmine_fixtures/people_spec.rb +++ b/spec/controllers/jasmine_fixtures/people_spec.rb @@ -14,7 +14,7 @@ describe PeopleController, :type => :controller do end it "generates a jasmine fixture trying an external search", :fixture => true do - get :index, :q => "sample@diaspor.us" + get :index, params: {q: "sample@diaspor.us"} save_fixture(html_for("body"), "pending_external_people_search") end end diff --git a/spec/controllers/jasmine_fixtures/photos_spec.rb b/spec/controllers/jasmine_fixtures/photos_spec.rb index fd62b21a6aef711c337d2f146c6162e016768dd6..3dabe5e53661e49a7334025dde5fee72eb97caa4 100644 --- a/spec/controllers/jasmine_fixtures/photos_spec.rb +++ b/spec/controllers/jasmine_fixtures/photos_spec.rb @@ -11,7 +11,7 @@ describe PhotosController, :type => :controller do describe '#index' do it "generates a jasmine fixture", :fixture => true do request.env['HTTP_ACCEPT'] = 'application/json' - get :index, :person_id => alice.person.guid.to_s + get :index, params: {person_id: alice.person.guid.to_s} save_fixture(response.body, "photos_json") end end diff --git a/spec/controllers/jasmine_fixtures/status_messages_spec.rb b/spec/controllers/jasmine_fixtures/status_messages_spec.rb index 905a5137ce7ab41b73b147e8d5546fe2dcf17306..6964f1d5b195e3356bd0585f6ddf8d686d38cfe2 100644 --- a/spec/controllers/jasmine_fixtures/status_messages_spec.rb +++ b/spec/controllers/jasmine_fixtures/status_messages_spec.rb @@ -25,7 +25,7 @@ describe StatusMessagesController, :type => :controller do aspect = alice.aspects.create(:name => 'people') contact.aspects << aspect contact.save - get :new, :person_id => bob.person.id + get :new, params: {person_id: bob.person.id} save_fixture(html_for("body"), "status_message_new") end end diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index b9935a70f9a32cb616e9b091a7177b7bdf5c39b3..b29fdeae92087fd4de4f6c077a258b0e6267eb9c 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -18,7 +18,7 @@ describe LikesController, type: :controller do context "on my own post" do it "succeeds" do @target = alice.post :status_message, text: "AWESOME", to: @alices_aspect.id - post :create, like_hash.merge(format: :json) + post :create, params: like_hash, format: :json expect(response.code).to eq("201") end end @@ -29,13 +29,13 @@ describe LikesController, type: :controller do end it "likes" do - post :create, like_hash + post :create, params: like_hash expect(response.code).to eq("201") end it "doesn't post multiple times" do alice.like!(@target) - post :create, like_hash + post :create, params: like_hash expect(response.code).to eq("422") end end @@ -47,7 +47,7 @@ describe LikesController, type: :controller do it "doesn't post" do expect(alice).not_to receive(:like!) - post :create, like_hash + post :create, params: like_hash expect(response.code).to eq("422") end end @@ -58,8 +58,7 @@ describe LikesController, type: :controller do end it "should be catched when it means that the target is not found" do - params = like_hash.merge(format: :json, post_id: -1) - post :create, params + post :create, params: {post_id: -1}, format: :json expect(response.code).to eq("422") end @@ -67,7 +66,7 @@ describe LikesController, type: :controller do @target = alice.post :status_message, text: "AWESOME", to: @alices_aspect.id allow(alice).to receive(:like!).and_raise("something") allow(@controller).to receive(:current_user).and_return(alice) - expect { post :create, like_hash.merge(format: :json) }.to raise_error("something") + expect { post :create, params: like_hash, format: :json }.to raise_error("something") end end end @@ -80,18 +79,18 @@ describe LikesController, type: :controller do it "returns a 404 for a post not visible to the user" do sign_in eve expect { - get :index, post_id: @message.id + get :index, params: {post_id: @message.id} }.to raise_error(ActiveRecord::RecordNotFound) end it "returns an array of likes for a post" do bob.like!(@message) - get :index, post_id: @message.id + get :index, params: {post_id: @message.id} expect(JSON.parse(response.body).map {|h| h["id"] }).to match_array(@message.likes.map(&:id)) end it "returns an empty array for a post with no likes" do - get :index, post_id: @message.id + get :index, params: {post_id: @message.id} expect(JSON.parse(response.body).map(&:id)).to eq([]) end end @@ -106,7 +105,7 @@ describe LikesController, type: :controller do current_user = controller.send(:current_user) expect(current_user).to receive(:retract).with(@like) - delete :destroy, format: :json, post_id: @message.id, id: @like.id + delete :destroy, params: {post_id: @message.id, id: @like.id}, format: :json expect(response.status).to eq(204) end @@ -114,7 +113,7 @@ describe LikesController, type: :controller do like2 = eve.like!(@message) like_count = Like.count - delete :destroy, format: :json, post_id: @message.id, id: like2.id + delete :destroy, params: {post_id: @message.id, id: like2.id}, format: :json expect(response.status).to eq(404) expect(response.body).to eq(I18n.t("likes.destroy.error")) expect(Like.count).to eq(like_count) diff --git a/spec/controllers/messages_controller_spec.rb b/spec/controllers/messages_controller_spec.rb index 6e7bea22830655bfcc09c382086e19ca1bae034d..596ca084e83547df399a42acb91cb7be7ec04ef4 100644 --- a/spec/controllers/messages_controller_spec.rb +++ b/spec/controllers/messages_controller_spec.rb @@ -32,7 +32,7 @@ describe MessagesController, :type => :controller do it 'redirects to conversation' do expect { - post :create, @message_params + post :create, params: @message_params }.to change(Message, :count).by(1) expect(response.status).to eq(302) expect(response).to redirect_to(conversations_path(:conversation_id => @conversation)) @@ -40,7 +40,7 @@ describe MessagesController, :type => :controller do it "dispatches the message" do expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).with(alice, instance_of(Message)) - post :create, @message_params + post :create, params: @message_params end end @@ -54,7 +54,7 @@ describe MessagesController, :type => :controller do it 'does not create the message' do expect { - post :create, @message_params + post :create, params: @message_params }.not_to change(Message, :count) expect(flash[:error]).to be_present end @@ -72,7 +72,7 @@ describe MessagesController, :type => :controller do end it 'comments' do - post :create, @message_params + post :create, params: @message_params expect(response.status).to eq(302) expect(response).to redirect_to(conversations_path(:conversation_id => @conversation)) end @@ -81,7 +81,7 @@ describe MessagesController, :type => :controller do new_user = FactoryGirl.create(:user) @message_params[:author_id] = new_user.person.id.to_s - post :create, @message_params + post :create, params: @message_params created_message = Message.find_by_text(@message_params[:message][:text]) expect(created_message.author).to eq(alice.person) end @@ -94,13 +94,13 @@ describe MessagesController, :type => :controller do ) @message_params[:id] = old_message.id - post :create, @message_params + post :create, params: @message_params expect(old_message.reload.text).to eq('hello') end it "dispatches the message" do expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).with(alice, instance_of(Message)) - post :create, @message_params + post :create, params: @message_params end end @@ -118,7 +118,7 @@ describe MessagesController, :type => :controller do it 'does not create the message' do expect { - post :create, @message_params + post :create, params: @message_params }.not_to change(Message, :count) expect(flash[:error]).to be_present end diff --git a/spec/controllers/node_info_controller_spec.rb b/spec/controllers/node_info_controller_spec.rb index 907f1183aff68320c807d8f690ec6ddb44b09ce5..3108ca4cfb527321cd0313524b3e6eba6969807b 100644 --- a/spec/controllers/node_info_controller_spec.rb +++ b/spec/controllers/node_info_controller_spec.rb @@ -25,7 +25,7 @@ describe NodeInfoController do describe "#document" do context "invalid version" do it "responds with not found" do - get :document, version: "0.0", format: :json + get :document, params: {version: "0.0"}, format: :json expect(response.code).to eq "404" end @@ -34,7 +34,7 @@ describe NodeInfoController do %w(1.0 2.0).each do |version| context "version #{version}" do it "responds to JSON" do - get :document, version: version, format: :json + get :document, params: {version: version}, format: :json expect(response).to be_success end @@ -43,11 +43,11 @@ describe NodeInfoController do expect(NodeInfoPresenter).to receive(:new).with(version) .and_return(double(as_json: {}, content_type: "application/json")) - get :document, version: version, format: :json + get :document, params: {version: version}, format: :json end it "notes the schema in the content type" do - get :document, version: version, format: :json + get :document, params: {version: version}, format: :json expect(response.content_type) .to eq("application/json; profile=http://nodeinfo.diaspora.software/ns/schema/#{version}#") diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index d1f969e7af8f361f5a13b3b26d162014e61781bd..58a078bcb1c8683c28a74a28c1ebdb08642450a6 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -10,23 +10,23 @@ describe NotificationsController, :type => :controller do describe '#update' do it 'marks a notification as read if it gets no other information' do note = FactoryGirl.create(:notification) - expect(Notification).to receive( :where ).and_return( [note] ) - expect(note).to receive( :set_read_state ).with( true ) - get :update, "id" => note.id, :format => :json + expect(Notification).to receive(:where).and_return([note]) + expect(note).to receive(:set_read_state).with(true) + get :update, params: {id: note.id}, format: :json end it 'marks a notification as read if it is told to' do note = FactoryGirl.create(:notification) - expect(Notification).to receive( :where ).and_return( [note] ) - expect(note).to receive( :set_read_state ).with( true ) - get :update, "id" => note.id, :set_unread => "false", :format => :json + expect(Notification).to receive(:where).and_return([note]) + expect(note).to receive(:set_read_state).with(true) + get :update, params: {id: note.id, set_unread: "false"}, format: :json end it 'marks a notification as unread if it is told to' do note = FactoryGirl.create(:notification) - expect(Notification).to receive( :where ).and_return( [note] ) - expect(note).to receive( :set_read_state ).with( false ) - get :update, "id" => note.id, :set_unread => "true", :format => :json + expect(Notification).to receive(:where).and_return([note]) + expect(note).to receive(:set_read_state).with(false) + get :update, params: {id: note.id, set_unread: "true"}, format: :json end it "marks a notification as unread without timestamping" do @@ -34,7 +34,7 @@ describe NotificationsController, :type => :controller do FactoryGirl.create(:notification, recipient: alice, unread: false) end - get :update, "id" => note.id, :set_unread => "true", :format => :json + get :update, params: {id: note.id, set_unread: "true"}, format: :json expect(response).to be_success updated_note = Notification.find(note.id) @@ -48,7 +48,7 @@ describe NotificationsController, :type => :controller do FactoryGirl.create(:notification, :recipient => alice) note = FactoryGirl.create(:notification, :recipient => user2) - get :update, "id" => note.id, :set_unread => "false", :format => :json + get :update, params: {id: note.id, set_unread: "false"}, format: :json expect(Notification.find(note.id).unread).to eq(true) end @@ -90,7 +90,7 @@ describe NotificationsController, :type => :controller do end it 'succeeds on mobile' do - get :index, :format => :mobile + get :index, format: :mobile expect(response).to be_success end @@ -98,33 +98,33 @@ describe NotificationsController, :type => :controller do 25.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) } get :index expect(assigns[:notifications].count).to eq(25) - get :index, "page" => 2 + get :index, params: {page: 2} expect(assigns[:notifications].count).to eq(1) end it "supports a limit per_page parameter" do 2.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) } - get :index, "per_page" => 2 + get :index, params: {per_page: 2} expect(assigns[:notifications].count).to eq(2) end describe "special case for start sharing notifications" do it "should not provide a contacts menu for standard notifications" do FactoryGirl.create(:notification, :recipient => alice, :target => @post) - get :index, "per_page" => 5 + get :index, params: {per_page: 5} expect(Nokogiri(response.body).css('.aspect_membership')).to be_empty end it "should provide a contacts menu for start sharing notifications" do eve.share_with(alice.person, eve.aspects.first) - get :index, "per_page" => 5 + get :index, params: {per_page: 5} expect(Nokogiri(response.body).css(".aspect_membership_dropdown")).not_to be_empty end it 'succeeds on mobile' do eve.share_with(alice.person, eve.aspects.first) - get :index, :format => :mobile + get :index, format: :mobile expect(response).to be_success end end @@ -132,7 +132,7 @@ describe NotificationsController, :type => :controller do describe "filter notifications" do it "supports filtering by notification type" do FactoryGirl.create(:notification, :recipient => alice, :type => "Notifications::StartedSharing") - get :index, "type" => "started_sharing" + get :index, params: {type: "started_sharing"} expect(assigns[:notifications].count).to eq(1) end @@ -140,7 +140,7 @@ describe NotificationsController, :type => :controller do FactoryGirl.create(:notification, :recipient => alice, :target => @post) get :read_all FactoryGirl.create(:notification, :recipient => alice, :target => @post) - get :index, "show" => "unread" + get :index, params: {show: "unread"} expect(assigns[:notifications].count).to eq(1) end end @@ -165,46 +165,54 @@ describe NotificationsController, :type => :controller do end describe "#read_all" do - it 'marks all notifications as read' do + let(:post) { FactoryGirl.create(:status_message) } + + it "marks all notifications as read" do request.env["HTTP_REFERER"] = "I wish I were spelled right" - FactoryGirl.create(:notification, :recipient => alice, :target => @post) - FactoryGirl.create(:notification, :recipient => alice, :target => @post) + FactoryGirl.create(:notification, recipient: alice, target: post) + FactoryGirl.create(:notification, recipient: alice, target: post) - expect(Notification.where(:unread => true).count).to eq(2) + expect(Notification.where(unread: true).count).to eq(2) get :read_all - expect(Notification.where(:unread => true).count).to eq(0) + expect(Notification.where(unread: true).count).to eq(0) end - it 'marks all notifications in the current filter as read' do + + it "marks all notifications in the current filter as read" do request.env["HTTP_REFERER"] = "I wish I were spelled right" - FactoryGirl.create(:notification, :recipient => alice, :target => @post) - FactoryGirl.create(:notification, :recipient => alice, :type => "Notifications::StartedSharing") - expect(Notification.where(:unread => true).count).to eq(2) - get :read_all, "type" => "started_sharing" - expect(Notification.where(:unread => true).count).to eq(1) + FactoryGirl.create(:notification, recipient: alice, target: post) + FactoryGirl.create(:notification, recipient: alice, type: "Notifications::StartedSharing") + expect(Notification.where(unread: true).count).to eq(2) + get :read_all, params: {type: "started_sharing"} + expect(Notification.where(unread: true).count).to eq(1) end + it "should redirect back in the html version if it has > 0 notifications" do - FactoryGirl.create(:notification, :recipient => alice, :type => "Notifications::StartedSharing") - get :read_all, :format => :html, "type" => "liked" + FactoryGirl.create(:notification, recipient: alice, type: "Notifications::StartedSharing") + get :read_all, params: {type: "liked"}, format: :html expect(response).to redirect_to(notifications_path) end + it "should redirect back in the mobile version if it has > 0 notifications" do - FactoryGirl.create(:notification, :recipient => alice, :type => "Notifications::StartedSharing") - get :read_all, :format => :mobile, "type" => "liked" + FactoryGirl.create(:notification, recipient: alice, type: "Notifications::StartedSharing") + get :read_all, params: {type: "liked"}, format: :mobile expect(response).to redirect_to(notifications_path) end + it "should redirect to stream in the html version if it has 0 notifications" do - FactoryGirl.create(:notification, :recipient => alice, :type => "Notifications::StartedSharing") - get :read_all, :format => :html, "type" => "started_sharing" + FactoryGirl.create(:notification, recipient: alice, type: "Notifications::StartedSharing") + get :read_all, params: {type: "started_sharing"}, format: :html expect(response).to redirect_to(stream_path) end + it "should redirect back in the mobile version if it has 0 notifications" do - FactoryGirl.create(:notification, :recipient => alice, :type => "Notifications::StartedSharing") - get :read_all, :format => :mobile, "type" => "started_sharing" + FactoryGirl.create(:notification, recipient: alice, type: "Notifications::StartedSharing") + get :read_all, params: {type: "started_sharing"}, format: :mobile expect(response).to redirect_to(stream_path) end + it "should return a dummy value in the json version" do - FactoryGirl.create(:notification, :recipient => alice, :target => @post) - get :read_all, :format => :json + FactoryGirl.create(:notification, recipient: alice, target: post) + get :read_all, format: :json expect(response).not_to be_redirect end end diff --git a/spec/controllers/participations_controller_spec.rb b/spec/controllers/participations_controller_spec.rb index f557188f1a5f258c1c16c17d0a8ab2ae1f68c535..9c2fc1e2c6fc670be83b65c1865ef093308fb88b 100644 --- a/spec/controllers/participations_controller_spec.rb +++ b/spec/controllers/participations_controller_spec.rb @@ -9,7 +9,7 @@ describe ParticipationsController, :type => :controller do shared_examples 'on a visible post' do it 'creates the participation' do - post :create, post_id: @post.id + post :create, params: {post_id: @post.id} expect(alice.participations.where(:target_id => @post.id)).to exist expect(response.code).to eq('201') end @@ -47,7 +47,7 @@ describe ParticipationsController, :type => :controller do end it 'should not create the participation' do - post :create, post_id: @post.id + post :create, params: {post_id: @post.id} expect(alice.participations.where(:target_id => @post.id)).not_to exist expect(response.code).to eq('403') end @@ -61,7 +61,7 @@ describe ParticipationsController, :type => :controller do before { alice.participate! post } it 'should remove participation' do - delete :destroy, post_id: post.id + delete :destroy, params: {post_id: post.id} expect(alice.participations.where(:target_id => post.id)).not_to exist expect(response.code).to eq('200') end @@ -69,7 +69,7 @@ describe ParticipationsController, :type => :controller do context 'on a post you do not partecipate to' do it 'says it is an unprocessable request' do - delete :destroy, post_id: post.id + delete :destroy, params: {post_id: post.id} expect(response.code).to eq('422') end end diff --git a/spec/controllers/passwords_controller_spec.rb b/spec/controllers/passwords_controller_spec.rb index 31c3d3e73d6a5372db78d3729b650a36aa44a38e..378e3a1119bb7583c5a6c4358322e0f3fb00feb6 100644 --- a/spec/controllers/passwords_controller_spec.rb +++ b/spec/controllers/passwords_controller_spec.rb @@ -10,23 +10,23 @@ describe Devise::PasswordsController, type: :controller do describe "#create" do context "when there is no such user" do it "succeeds" do - post :create, "user" => {"email" => "foo@example.com"} + post :create, params: {user: {email: "foo@example.com"}} expect(response).to be_success end it "doesn't send email" do expect(Workers::ResetPassword).not_to receive(:perform_async) - post :create, "user" => {"email" => "foo@example.com"} + post :create, params: {user: {email: "foo@example.com"}} end end context "when there is a user with that email" do it "redirects to the login page" do - post :create, "user" => {"email" => alice.email} + post :create, params: {user: {email: alice.email}} expect(response).to redirect_to(new_user_session_path) end it "sends email (enqueued to Sidekiq)" do expect(Workers::ResetPassword).to receive(:perform_async).with(alice.id) - post :create, "user" => {"email" => alice.email} + post :create, params: {user: {email: alice.email}} end end end diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 84624492787f2108f59a574cb3d575c02942f4de..bb450b88cb85793f287ab8a6ad3c247701e87bb1 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -30,24 +30,24 @@ describe PeopleController, :type => :controller do describe 'via json' do it 'succeeds' do - get :index, :q => "Korth", :format => 'json' + get :index, params: {q: "Korth"}, format: :json expect(response).to be_success end it 'responds with json' do - get :index, :q => "Korth", :format => 'json' + get :index, params: {q: "Korth"}, format: :json expect(response.body).to eq([@korth].to_json) end it 'does not assign hashes' do - get :index, :q => "Korth", :format => 'json' + get :index, params: {q: "Korth"}, format: :json expect(assigns[:hashes]).to be_nil end it "doesn't include closed accounts" do - get :index, q: "Closed", format: "json" + get :index, params: {q: "Closed"}, format: :json expect(JSON.parse(response.body).size).to eq(0) - get :index, q: @closed.diaspora_handle, format: "json" + get :index, params: {q: @closed.diaspora_handle}, format: :json expect(JSON.parse(response.body).size).to eq(0) end end @@ -60,39 +60,39 @@ describe PeopleController, :type => :controller do :last_name => "w", :searchable => false)) end it 'finds people even if they have searchable off' do - get :index, :q => "eugene@example.org" + get :index, params: {q: "eugene@example.org"} expect(assigns[:people][0].id).to eq(@unsearchable_eugene.id) end it 'downcases the query term' do - get :index, :q => "Eugene@Example.ORG" + get :index, params: {q: "Eugene@Example.ORG"} expect(assigns[:people][0].id).to eq(@unsearchable_eugene.id) end it 'does not the background query task if the user is found' do - get :index, :q => "Eugene@Example.ORG" + get :index, params: {q: "Eugene@Example.ORG"} expect(assigns[:background_query]).to eq(nil) end it 'sets background query task if the user is not found' do - get :index, :q => "Eugene@Example1.ORG" + get :index, params: {q: "Eugene@Example1.ORG"} expect(assigns[:background_query]).to eq("eugene@example1.org") end it "doesn't include closed accounts" do - get :index, q: @closed.diaspora_handle + get :index, params: {q: @closed.diaspora_handle} expect(assigns[:people].size).to eq(0) end end context 'query is not a tag or a diaspora ID' do it 'assigns hashes' do - get :index, :q => "Korth" + get :index, params: {q: "Korth"} expect(assigns[:hashes]).not_to be_nil end it 'does not set the background query task' do - get :index, :q => "Korth" + get :index, params: {q: "Korth"} expect(assigns[:background_query]).not_to be_present end @@ -100,29 +100,29 @@ describe PeopleController, :type => :controller do eugene2 = FactoryGirl.create(:person, :profile => FactoryGirl.build(:profile, :first_name => "Eugene", :last_name => "w")) - get :index, :q => "Eug" + get :index, params: {q: "Eug"} expect(assigns[:people].map { |x| x.id }).to match_array([@eugene.id, eugene2.id]) end it "succeeds if there is exactly one match" do - get :index, :q => "Korth" + get :index, params: {q: "Korth"} expect(assigns[:people].length).to eq(1) expect(response).to be_success end it "succeeds if there are no matches" do - get :index, :q => "Korthsauce" + get :index, params: {q: "Korthsauce"} expect(assigns[:people].length).to eq(0) expect(response).to be_success end it 'succeeds if you search for the empty term' do - get :index, :q => '' + get :index, params: {q: ""} expect(response).to be_success end it 'succeeds if you search for punctuation' do - get :index, :q => '+' + get :index, params: {q: "+"} expect(response).to be_success end @@ -130,12 +130,12 @@ describe PeopleController, :type => :controller do eugene2 = FactoryGirl.create(:person, :profile => FactoryGirl.build(:profile, :first_name => "Eugene", :last_name => "w", :searchable => false)) - get :index, :q => "Eug" + get :index, params: {q: "Eug"} expect(assigns[:people]).not_to match_array([eugene2]) end it "doesn't include closed accounts" do - get :index, q: "Closed" + get :index, params: {q: "Closed"} expect(assigns[:people].size).to eq(0) end end @@ -164,7 +164,7 @@ describe PeopleController, :type => :controller do it 'takes time' do expect(Benchmark.realtime { - get :show, :id => @user.person.to_param + get :show, params: {id: @user.person.to_param} }).to be < 1.0 end end @@ -176,44 +176,44 @@ describe PeopleController, :type => :controller do end it "404s if the id is invalid" do - get :show, :id => 'delicious' + get :show, params: {id: "delicious"} expect(response.code).to eq("404") end it "404s if no person is found via id" do - get :show, :id => "3d920397846" + get :show, params: {id: "3d920397846"} expect(response.code).to eq("404") end it "404s if no person is found via username" do - get :show, :username => 'delicious' + get :show, params: {username: "delicious"} expect(response.code).to eq("404") end it "returns a person presenter" do expect(PersonPresenter).to receive(:new).with(@person, @user).and_return(@presenter) - get :show, username: @person.username + get :show, params: {username: @person.username} expect(assigns(:presenter).to_json).to eq(@presenter.to_json) end it 'finds a person via username' do - get :show, username: @person.username + get :show, params: {username: @person.username} expect(assigns(:presenter).to_json).to eq(@presenter.to_json) end it "404s if no person is found via diaspora handle" do - get :show, :username => 'delicious@pod.net' + get :show, params: {username: "delicious@pod.net"} expect(response.code).to eq("404") end it 'finds a person via diaspora handle' do - get :show, username: @person.diaspora_handle + get :show, params: {username: @person.diaspora_handle} expect(assigns(:presenter).to_json).to eq(@presenter.to_json) end it 'redirects home for closed account' do @person = FactoryGirl.create(:person, :closed_account => true) - get :show, :id => @person.to_param + get :show, params: {id: @person.to_param} expect(response).to be_redirect expect(flash[:notice]).not_to be_blank end @@ -222,7 +222,7 @@ describe PeopleController, :type => :controller do user2 = bob profile = user2.profile profile.update_attribute(:first_name, "</script><script> alert('xss attack');</script>") - get :show, :id => user2.person.to_param + get :show, params: {id: user2.person.to_param} expect(response).to be_success expect(response.body).not_to include(profile.first_name) end @@ -231,27 +231,27 @@ describe PeopleController, :type => :controller do 16.times do |i| eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => true) end - get :show, :id => eve.person.to_param + get :show, params: {id: eve.person.to_param} expect(response.body).to include ',"photos_count":16' eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => false) - get :show, :id => eve.person.to_param + get :show, params: {id: eve.person.to_param} expect(response.body).to include ',"photos_count":16' # eve is not sharing with alice end context "when the person is the current user" do it "succeeds" do - get :show, :id => @user.person.to_param + get :show, params: {id: @user.person.to_param} expect(response).to be_success end it 'succeeds on the mobile site' do - get :show, :id => @user.person.to_param, :format => :mobile + get :show, params: {id: @user.person.to_param}, format: :mobile expect(response).to be_success end it "assigns the right person" do - get :show, id: @person.to_param + get :show, params: {id: @person.to_param} expect(assigns(:presenter).id).to eq(@presenter.id) end end @@ -263,25 +263,25 @@ describe PeopleController, :type => :controller do end it "succeeds" do - get :show, :id => @person.to_param + get :show, params: {id: @person.to_param} expect(response.status).to eq(200) end it 'succeeds on the mobile site' do - get :show, :id => @person.to_param, :format => :mobile + get :show, params: {id: @person.to_param}, format: :mobile expect(response).to be_success end it 'forces to sign in if the person is remote' do p = FactoryGirl.create(:person) - get :show, :id => p.to_param + get :show, params: {id: p.to_param} expect(response).to be_redirect expect(response).to redirect_to new_user_session_path end it "leaks no private profile info" do - get :show, id: @person.to_param + get :show, params: {id: @person.to_param} expect(response.body).not_to include(@person.profile.bio) end @@ -296,7 +296,7 @@ describe PeopleController, :type => :controller do last_name: {html_attribute: "property", name: "og:profile:last_name"} } - get :show, id: @person.to_param + get :show, params: {id: @person.to_param} methods_properties.each do |method, property| value = presenter.send(method) @@ -313,12 +313,12 @@ describe PeopleController, :type => :controller do end it "succeeds" do - get :show, :id => @person.to_param + get :show, params: {id: @person.to_param} expect(response).to be_success end it 'succeeds on the mobile site' do - get :show, :id => @person.to_param, :format => :mobile + get :show, params: {id: @person.to_param}, format: :mobile expect(response).to be_success end @@ -326,18 +326,18 @@ describe PeopleController, :type => :controller do note = FactoryGirl.create(:notification, :recipient => @user, :target => @person, :unread => true) expect { - get :show, :id => @person.to_param + get :show, params: {id: @person.to_param} note.reload }.to change(Notification.where(:unread => true), :count).by(-1) end it "includes private profile info" do - get :show, id: @person.to_param + get :show, params: {id: @person.to_param} expect(response.body).to include(@person.profile.bio) end it "preloads data using gon for the aspect memberships dropdown" do - get :show, id: @person.to_param + get :show, params: {id: @person.to_param} expect_gon_preloads_for_aspect_membership_dropdown(:person, true) end end @@ -348,22 +348,22 @@ describe PeopleController, :type => :controller do end it "succeeds" do - get :show, :id => @person.to_param + get :show, params: {id: @person.to_param} expect(response).to be_success end it 'succeeds on the mobile site' do - get :show, :id => @person.to_param, :format => :mobile + get :show, params: {id: @person.to_param}, format: :mobile expect(response).to be_success end it "leaks no private profile info" do - get :show, id: @person.to_param + get :show, params: {id: @person.to_param} expect(response.body).not_to include(@person.profile.bio) end it "preloads data using gon for the aspect memberships dropdown" do - get :show, id: @person.to_param + get :show, params: {id: @person.to_param} expect_gon_preloads_for_aspect_membership_dropdown(:person, false) end end @@ -376,7 +376,7 @@ describe PeopleController, :type => :controller do end it "leaks no private profile info" do - get :show, id: @person.to_param + get :show, params: {id: @person.to_param} expect(response.body).not_to include(@person.profile.bio) end end @@ -384,7 +384,7 @@ describe PeopleController, :type => :controller do describe '#stream' do it "redirects non-json requests" do - get :stream, person_id: @user.person.to_param + get :stream, params: {person_id: @user.person.to_param} expect(response).to be_redirect end @@ -395,7 +395,7 @@ describe PeopleController, :type => :controller do @user.post(:status_message, :text => "to all aspects", :to => 'all') @user.post(:status_message, :text => "public", :to => 'all', :public => true) expect(@user.reload.posts.length).to eq(3) - get :stream, person_id: @user.person.to_param, format: :json + get :stream, params: {person_id: @user.person.to_param}, format: :json expect(assigns(:stream).posts.map(&:id)).to match_array(@user.posts.map(&:id)) end @@ -403,7 +403,7 @@ describe PeopleController, :type => :controller do cmmt = 'I mean it' message = @user.post :status_message, :text => 'test more', :to => @aspect.id @user.comment!(message, cmmt) - get :stream, person_id: @user.person.to_param, format: :json + get :stream, params: {person_id: @user.person.to_param}, format: :json expect(response).to be_success expect(response.body).to include(cmmt) end @@ -416,7 +416,7 @@ describe PeopleController, :type => :controller do it "includes reshares" do reshare = @user.post(:reshare, :public => true, :root_guid => FactoryGirl.create(:status_message, :public => true).guid, :to => alice.aspect_ids) - get :stream, person_id: @user.person.to_param, format: :json + get :stream, params: {person_id: @user.person.to_param}, format: :json expect(assigns[:stream].posts.map { |x| x.id }).to include(reshare.id) end @@ -431,7 +431,7 @@ describe PeopleController, :type => :controller do posts_user_can_see << bob.post(:status_message, :text => "public", :to => 'all', :public => true) expect(bob.reload.posts.length).to eq(4) - get :stream, person_id: @person.to_param, format: :json + get :stream, params: {person_id: @person.to_param}, format: :json expect(assigns(:stream).posts.map(&:id)).to match_array(posts_user_can_see.map(&:id)) end end @@ -448,13 +448,13 @@ describe PeopleController, :type => :controller do public_post = eve.post(:status_message, :text => "public", :to => 'all', :public => true) expect(eve.reload.posts.length).to eq(3) - get :stream, person_id: @person.to_param, format: :json + get :stream, params: {person_id: @person.to_param}, format: :json expect(assigns[:stream].posts.map(&:id)).to match_array([public_post].map(&:id)) end it "posts include reshares" do reshare = @user.post(:reshare, :public => true, :root_guid => FactoryGirl.create(:status_message, :public => true).guid, :to => alice.aspect_ids) - get :stream, person_id: @user.person.to_param, format: :json + get :stream, params: {person_id: @user.person.to_param}, format: :json expect(assigns[:stream].posts.map { |x| x.id }).to include(reshare.id) end end @@ -478,17 +478,17 @@ describe PeopleController, :type => :controller do it "posts include reshares" do reshare = @user.post(:reshare, :public => true, :root_guid => FactoryGirl.create(:status_message, :public => true).guid, :to => alice.aspect_ids) - get :stream, person_id: @user.person.to_param, format: :json + get :stream, params: {person_id: @user.person.to_param}, format: :json expect(assigns[:stream].posts.map { |x| x.id }).to include(reshare.id) end it "assigns only public posts" do - get :stream, person_id: @person.to_param, format: :json + get :stream, params: {person_id: @person.to_param}, format: :json expect(assigns[:stream].posts.map(&:id)).to match_array(@public_posts.map(&:id)) end it 'is sorted by created_at desc' do - get :stream, person_id: @person.to_param, format: :json + get :stream, params: {person_id: @person.to_param}, format: :json expect(assigns[:stream].stream_posts).to eq(@public_posts.sort_by { |p| p.created_at }.reverse) end end @@ -503,19 +503,19 @@ describe PeopleController, :type => :controller do end it 'redirects html requests' do - get :hovercard, :person_id => @hover_test.guid + get :hovercard, params: {person_id: @hover_test.guid} expect(response).to redirect_to person_path(:id => @hover_test.guid) end it 'returns json with profile stuff' do - get :hovercard, :person_id => @hover_test.guid, :format => 'json' + get :hovercard, params: {person_id: @hover_test.guid}, format: :json expect(JSON.parse(response.body)["diaspora_id"]).to eq(@hover_test.diaspora_handle) end it "returns contact when sharing" do alice.share_with(@hover_test, alice.aspects.first) expect(@controller).to receive(:current_user).at_least(:once).and_return(alice) - get :hovercard, person_id: @hover_test.guid, format: "json" + get :hovercard, params: {person_id: @hover_test.guid}, format: :json expect(JSON.parse(response.body)["contact"]).not_to be_falsy end @@ -525,13 +525,13 @@ describe PeopleController, :type => :controller do end it "succeeds with local person" do - get :hovercard, person_id: bob.person.guid, format: :json + get :hovercard, params: {person_id: bob.person.guid}, format: :json expect(response.status).to eq(200) expect(JSON.parse(response.body)["diaspora_id"]).to eq(bob.diaspora_handle) end it "succeeds with remote person" do - get :hovercard, person_id: remote_raphael.guid, format: :json + get :hovercard, params: {person_id: remote_raphael.guid}, format: :json expect(response.status).to eq(200) expect(JSON.parse(response.body)["diaspora_id"]).to eq(remote_raphael.diaspora_handle) end @@ -557,22 +557,22 @@ describe PeopleController, :type => :controller do describe "via json" do it "returns no data when a search fails" do - get :refresh_search, q: "weweweKorth", format: "json" + get :refresh_search, params: {q: "weweweKorth"}, format: :json expect(response.body).to eq({search_html: "", contacts: nil}.to_json) end it "returns no data unless a fully composed name is sent" do - get :refresh_search, q: "Korth" + get :refresh_search, params: {q: "Korth"} expect(response.body).to eq({search_html: "", contacts: nil}.to_json) end it "returns with a found name" do - get :refresh_search, q: @korth.diaspora_handle + get :refresh_search, params: {q: @korth.diaspora_handle} expect(JSON.parse(response.body)["contacts"].size).to eq(1) end it "doesn't include closed accounts" do - get :refresh_search, q: @closed.diaspora_handle + get :refresh_search, params: {q: @closed.diaspora_handle} expect(JSON.parse(response.body)["contacts"]).to be_nil end end @@ -583,13 +583,13 @@ describe PeopleController, :type => :controller do it 'assigns the contacts of a person' do contact = alice.contact_for(bob.person) contacts = contact.contacts - get :contacts, :person_id => bob.person.to_param + get :contacts, params: {person_id: bob.person.to_param} expect(assigns(:contacts_of_contact).to_a).to eq(contacts.to_a) expect(response).to be_success end it 'shows an error when invalid person id' do - get :contacts, :person_id => 'foo' + get :contacts, params: {person_id: "foo"} expect(flash[:error]).to be_present expect(response).to redirect_to people_path end @@ -598,16 +598,16 @@ describe PeopleController, :type => :controller do 16.times do |i| eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => true) end - get :contacts, :person_id => eve.person.to_param + get :contacts, params: {person_id: eve.person.to_param} expect(response.body).to include ',"photos_count":16' eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => false) - get :contacts, :person_id => eve.person.to_param + get :contacts, params: {person_id: eve.person.to_param} expect(response.body).to include ',"photos_count":16' # eve is not sharing with alice end it "returns a 406 for json format" do - get :contacts, person_id: "foo", format: :json + get :contacts, params: {person_id: "foo"}, format: :json expect(response.code).to eq("406") end end diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 9b76fffe5a5e0021564e89fbc1fe8a409308706f..d323ba87b613e65ae8393e8822539a62d26e4b3f 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -24,18 +24,18 @@ describe PhotosController, :type => :controller do it 'accepts a photo from a regular form submission' do expect { - post :create, @params + post :create, params: @params }.to change(Photo, :count).by(1) end it 'returns application/json when possible' do request.env['HTTP_ACCEPT'] = 'application/json' - expect(post(:create, @params).headers['Content-Type']).to match 'application/json.*' + expect(post(:create, params: @params).headers["Content-Type"]).to match "application/json.*" end it 'returns text/html by default' do request.env['HTTP_ACCEPT'] = 'text/html,*/*' - expect(post(:create, @params).headers['Content-Type']).to match 'text/html.*' + expect(post(:create, params: @params).headers["Content-Type"]).to match "text/html.*" end end @@ -47,57 +47,57 @@ describe PhotosController, :type => :controller do it "creates a photo" do expect { - post :create, @params + post :create, params: @params }.to change(Photo, :count).by(1) end it "doesn't allow mass assignment of person" do new_user = FactoryGirl.create(:user) @params[:photo][:author] = new_user - post :create, @params + post :create, params: @params expect(Photo.last.author).to eq(alice.person) end it "doesn't allow mass assignment of person_id" do new_user = FactoryGirl.create(:user) @params[:photo][:author_id] = new_user.id - post :create, @params + post :create, params: @params expect(Photo.last.author).to eq(alice.person) end it 'can set the photo as the profile photo' do old_url = alice.person.profile.image_url @params[:photo][:set_profile_photo] = true - post :create, @params + post :create, params: @params expect(alice.reload.person.profile.image_url).not_to eq(old_url) end end describe '#index' do it "succeeds without any available pictures" do - get :index, :person_id => FactoryGirl.create(:person).guid.to_s + get :index, params: {person_id: FactoryGirl.create(:person).guid} expect(response).to be_success end it "succeeds on mobile devices without any available pictures" do - get :index, format: :mobile, person_id: FactoryGirl.create(:person).guid.to_s + get :index, params: {person_id: FactoryGirl.create(:person).guid}, format: :mobile expect(response).to be_success end it "succeeds on mobile devices with available pictures" do - get :index, format: :mobile, person_id: bob.person.guid.to_s + get :index, params: {person_id: bob.person.guid}, format: :mobile expect(response).to be_success end it "displays the logged in user's pictures" do - get :index, :person_id => alice.person.guid.to_s + get :index, params: {person_id: alice.person.guid} expect(assigns[:person]).to eq(alice.person) expect(assigns[:posts]).to eq([@alices_photo]) end it "displays another person's pictures" do - get :index, :person_id => bob.person.guid.to_s + get :index, params: {person_id: bob.person.guid} expect(assigns[:person]).to eq(bob.person) expect(assigns[:posts]).to eq([@bobs_photo]) end @@ -106,25 +106,24 @@ describe PhotosController, :type => :controller do 16.times do |i| eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => true) end - get :index, :person_id => eve.person.to_param + get :index, params: {person_id: eve.person.to_param} expect(response.body).to include ',"photos_count":16' eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => false) - get :index, :person_id => eve.person.to_param + get :index, params: {person_id: eve.person.to_param} expect(response.body).to include ',"photos_count":16' # eve is not sharing with alice end it "returns json when requested" do request.env['HTTP_ACCEPT'] = 'application/json' - get :index, :person_id => alice.person.guid.to_s + get :index, params: {person_id: alice.person.guid} expect(response.headers['Content-Type']).to match 'application/json.*' end it 'displays by date of creation' do max_time = bob.photos.first.created_at - 1.day - get :index, person_id: bob.person.guid.to_s, - max_time: max_time.to_i + get :index, params: {person_id: bob.person.guid, max_time: max_time.to_i} expect(assigns[:posts]).to be_empty end @@ -136,19 +135,19 @@ describe PhotosController, :type => :controller do end it "succeeds" do - get :index, person_id: @person.to_param + get :index, params: {person_id: @person.to_param} expect(response.status).to eq(200) end it "succeeds on the mobile site" do - get :index, person_id: @person.to_param, format: :mobile + get :index, params: {person_id: @person.to_param}, format: :mobile expect(response).to be_success end it "forces to sign in if the person is remote" do p = FactoryGirl.create(:person) - get :index, person_id: p.to_param + get :index, params: {person_id: p.to_param} expect(response).to be_redirect expect(response).to redirect_to new_user_session_path end @@ -157,16 +156,16 @@ describe PhotosController, :type => :controller do 16.times do eve.post(:photo, user_file: uploaded_photo, to: eve.aspects.first.id, public: true) end - get :index, person_id: eve.person.to_param + get :index, params: {person_id: eve.person.to_param} expect(response.body).to include ',"photos_count":16' eve.post(:photo, user_file: uploaded_photo, to: eve.aspects.first.id, public: false) - get :index, person_id: eve.person.to_param + get :index, params: {person_id: eve.person.to_param} expect(response.body).to include ',"photos_count":16' end it "displays a person's pictures" do - get :index, person_id: bob.person.guid.to_s + get :index, params: {person_id: bob.person.guid} expect(assigns[:person]).to eq(bob.person) expect(assigns[:posts]).to eq([@bobs_photo]) end @@ -175,42 +174,42 @@ describe PhotosController, :type => :controller do describe '#destroy' do it 'let a user delete his message' do - delete :destroy, :id => @alices_photo.id + delete :destroy, params: {id: @alices_photo.id} expect(Photo.find_by_id(@alices_photo.id)).to be_nil end it 'will let you delete your profile picture' do - xhr :get, :make_profile_photo, :photo_id => @alices_photo.id, :format => :js - delete :destroy, :id => @alices_photo.id + get :make_profile_photo, params: {photo_id: @alices_photo.id}, xhr: true, format: :js + delete :destroy, params: {id: @alices_photo.id}, format: :json expect(Photo.find_by_id(@alices_photo.id)).to be_nil end it 'sends a retraction on delete' do allow(@controller).to receive(:current_user).and_return(alice) expect(alice).to receive(:retract).with(@alices_photo) - delete :destroy, :id => @alices_photo.id + delete :destroy, params: {id: @alices_photo.id} end it 'will not let you destroy posts visible to you' do - delete :destroy, :id => @bobs_photo.id + delete :destroy, params: {id: @bobs_photo.id} expect(Photo.find_by_id(@bobs_photo.id)).to be_truthy end it 'will not let you destroy posts you do not own' do eves_photo = eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => true) - delete :destroy, :id => eves_photo.id + delete :destroy, params: {id: eves_photo.id} expect(Photo.find_by_id(eves_photo.id)).to be_truthy end end describe "#make_profile_photo" do it 'should return a 201 on a js success' do - xhr :get, :make_profile_photo, :photo_id => @alices_photo.id, :format => 'js' + get :make_profile_photo, params: {photo_id: @alices_photo.id}, xhr: true, format: :js expect(response.code).to eq("201") end it 'should return a 422 on failure' do - get :make_profile_photo, :photo_id => @bobs_photo.id + get :make_profile_photo, params: {photo_id: @bobs_photo.id} expect(response.code).to eq("422") end end @@ -218,19 +217,19 @@ describe PhotosController, :type => :controller do describe "#show" do it 'should return 404 for nonexistent stuff on mobile devices' do expect { - get :show, :person_id => bob.person.guid, :id => 772831, :format => 'mobile' + get :show, params: {person_id: bob.person.guid, id: 772_831}, format: :mobile }.to raise_error ActiveRecord::RecordNotFound end it 'should return 200 for existing stuff on mobile devices' do - get :show, :person_id => alice.person.guid, :id => @alices_photo.id, :format => 'mobile' + get :show, params: {person_id: alice.person.guid, id: @alices_photo.id}, format: :mobile expect(response).to be_success end it "doesn't leak private photos to the public" do sign_out :user expect { - get :show, :person_id => alice.person.guid, :id => @alices_photo.id, :format => 'mobile' + get :show, params: {person_id: alice.person.guid, id: @alices_photo.id}, format: :mobile }.to raise_error ActiveRecord::RecordNotFound end end diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index efbc1d8dda3c9fa644434cab384f84c082eaa5c1..28216a97e7949c45f2dd2e9fe0ec19f50c710ffd 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -16,7 +16,7 @@ describe PostsController, type: :controller do it "succeeds" do expect_any_instance_of(PostService).to receive(:mark_user_notifications).with(post.id) - get :show, id: post.id + get :show, params: {id: post.id} expect(response).to be_success end @@ -29,12 +29,12 @@ describe PostsController, type: :controller do expect(msg.mentioned_people.count).to eq(1) user.destroy - get :show, id: msg.id + get :show, params: {id: msg.id} expect(response).to be_success end it "renders the application layout on mobile" do - get :show, id: post.id, format: :mobile + get :show, params: {id: post.id}, format: :mobile expect(response).to render_template("layouts/application") end @@ -42,7 +42,7 @@ describe PostsController, type: :controller do reshare_id = FactoryGirl.create(:reshare, author: alice.person).id expect_any_instance_of(PostService).to receive(:mark_user_notifications).with(reshare_id) - get :show, id: reshare_id, format: :mobile + get :show, params: {id: reshare_id}, format: :mobile expect(response).to be_success end end @@ -54,7 +54,7 @@ describe PostsController, type: :controller do it "returns a 404" do expect { - get :show, id: post.id + get :show, params: {id: post.id} }.to raise_error ActiveRecord::RecordNotFound end end @@ -66,13 +66,13 @@ describe PostsController, type: :controller do let(:public_with_tags) { alice.post(:status_message, text: "#hi #howareyou", public: true) } it "shows a public post" do - get :show, id: public.id + get :show, params: {id: public.id} expect(response.body).to match "hello" end it "succeeds for statusnet" do @request.env["HTTP_ACCEPT"] = "application/html+xml,text/html" - get :show, id: public.id + get :show, params: {id: public.id} expect(response.body).to match "hello" end @@ -88,7 +88,7 @@ describe PostsController, type: :controller do author_name: {html_attribute: "property", name: "og:article:author"} } - get :show, id: public.id, format: :html + get :show, params: {id: public.id}, format: :html methods_properties.each do |method, property| value = presenter.send(method) @@ -99,7 +99,7 @@ describe PostsController, type: :controller do end it "includes the correct multiple meta tags" do - get :show, id: public_with_tags.id, format: :html + get :show, params: {id: public_with_tags.id}, format: :html expect(response.body).to include('<meta property="og:article:tag" content="hi" />') expect(response.body).to include('<meta property="og:article:tag" content="howareyou" />') @@ -108,7 +108,7 @@ describe PostsController, type: :controller do context "given a limited post" do it "forces the user to sign" do - get :show, id: post.id + get :show, params: {id: post.id} expect(response).to be_redirect expect(response).to redirect_to new_user_session_path end @@ -119,12 +119,12 @@ describe PostsController, type: :controller do describe "oembed" do it "works when you can see it" do sign_in alice - get :oembed, url: "/posts/#{post.id}" + get :oembed, params: {url: "/posts/#{post.id}"} expect(response.body).to match /iframe/ end it "returns a 404 response when the post is not found" do - get :oembed, url: "/posts/#{post.id}" + get :oembed, params: {url: "/posts/#{post.id}"} expect(response.status).to eq(404) end end @@ -132,13 +132,13 @@ describe PostsController, type: :controller do describe "#interactions" do context "user not signed in" do it "returns a 401 for private posts and format json" do - get :interactions, id: post.id, format: :json + get :interactions, params: {id: post.id}, format: :json expect(response.status).to eq(401) expect(JSON.parse(response.body)["error"]).to eq(I18n.t("devise.failure.unauthenticated")) end it "returns a 406 for private posts and format html" do - get :interactions, id: post.id + get :interactions, params: {id: post.id} expect(response.status).to eq(406) end end @@ -149,13 +149,13 @@ describe PostsController, type: :controller do end it "shows interactions of a post as json" do - get :interactions, id: post.id, format: :json + get :interactions, params: {id: post.id}, format: :json expect(response.body).to eq(PostInteractionPresenter.new(post, alice).to_json) end it "returns a 406 for format html" do sign_in alice - get :interactions, id: post.id + get :interactions, params: {id: post.id} expect(response.status).to eq(406) end end @@ -168,12 +168,12 @@ describe PostsController, type: :controller do end it "returns status 204 without a :q parameter" do - get :mentionable, id: post.id, format: :json + get :mentionable, params: {id: post.id}, format: :json expect(response.status).to eq(204) end it "responses status 406 (not acceptable) on html request" do - get :mentionable, id: post.id, q: "whatever", format: :html + get :mentionable, params: {id: post.id, q: "whatever"}, format: :html expect(response.status).to eq(406) end @@ -181,13 +181,13 @@ describe PostsController, type: :controller do expect(post_service).to receive(:find!) do raise ActiveRecord::RecordNotFound end - get :mentionable, id: post.id, q: "whatever", format: :json + get :mentionable, params: {id: post.id, q: "whatever"}, format: :json expect(response.status).to eq(404) end it "calls PostService#mentionable_in_comment and passes the result as a response" do expect(post_service).to receive(:mentionable_in_comment).with(post.id.to_s, "whatever").and_return([bob.person]) - get :mentionable, id: post.id, q: "whatever", format: :json + get :mentionable, params: {id: post.id, q: "whatever"}, format: :json expect(response.status).to eq(200) expect(response.body).to eq([bob.person].to_json) end @@ -196,7 +196,7 @@ describe PostsController, type: :controller do context "without a user signed in" do it "returns 401" do allow(post_service).to receive(:mentionable_in_comment).and_return([]) - get :mentionable, id: post.id, q: "whatever", format: :json + get :mentionable, params: {id: post.id, q: "whatever"}, format: :json expect(response.status).to eq(401) expect(JSON.parse(response.body)["error"]).to eq(I18n.t("devise.failure.unauthenticated")) end @@ -212,12 +212,12 @@ describe PostsController, type: :controller do it "works when it is your post" do expect_any_instance_of(PostService).to receive(:destroy).with(post.id.to_s) - delete :destroy, format: :json, id: post.id + delete :destroy, params: {id: post.id}, format: :json expect(response.status).to eq(204) end it "redirects to stream on mobile" do - delete :destroy, format: :mobile, id: post.id + delete :destroy, params: {id: post.id}, format: :mobile expect(response).to be_redirect expect(response).to redirect_to stream_path end @@ -227,7 +227,7 @@ describe PostsController, type: :controller do it "will respond with a 403" do sign_in bob, scope: :user - delete :destroy, format: :json, id: post.id + delete :destroy, params: {id: post.id}, format: :json expect(response.body).to eq("You are not allowed to do that") expect(response.status).to eq(403) end @@ -236,7 +236,7 @@ describe PostsController, type: :controller do sign_in eve, scope: :user expect { - delete :destroy, format: :json, id: post.id + delete :destroy, params: {id: post.id}, format: :json }.to raise_error ActiveRecord::RecordNotFound end end diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb index 9a6a47e8ee10a507b90083c6962d5ce43d6d11ce..802d4b0e6f271e3f6b33a95c2d07f15045674a84 100644 --- a/spec/controllers/profiles_controller_spec.rb +++ b/spec/controllers/profiles_controller_spec.rb @@ -15,7 +15,7 @@ describe ProfilesController, :type => :controller do expect(Person).to receive(:find_by_guid!).with("12345").and_return(mock_person) expect(PersonPresenter).to receive(:new).with(mock_person, eve).and_return(mock_presenter) - get :show, :id => 12345, :format => :json + get :show, params: {id: 12_345}, format: :json expect(response.body).to eq({:rock_star => "Jamie Cai"}.to_json) end end @@ -44,17 +44,19 @@ describe ProfilesController, :type => :controller do describe '#update' do it "sets the flash" do - put :update, :profile => { - :image_url => "", - :first_name => "Will", - :last_name => "Smith" + put :update, params: { + profile: { + image_url: "", + first_name: "Will", + last_name: "Smith" } + } expect(flash[:notice]).not_to be_blank end it "sets nsfw" do expect(eve.person(true).profile.nsfw).to eq(false) - put :update, :profile => { :id => eve.person.id, :nsfw => "1" } + put :update, params: {profile: {id: eve.person.id, nsfw: "1"}} expect(eve.person(true).profile.nsfw).to eq(true) end @@ -63,7 +65,7 @@ describe ProfilesController, :type => :controller do eve.person.profile.save expect(eve.person(true).profile.nsfw).to eq(true) - put :update, :profile => { :id => eve.person.id } + put :update, params: {profile: {id: eve.person.id}} expect(eve.person(true).profile.nsfw).to eq(false) end @@ -72,7 +74,7 @@ describe ProfilesController, :type => :controller do :tags => '#apples #oranges', :profile => {:tag_string => ''} } - put :update, params + put :update, params: params expect(eve.person(true).profile.tag_list.to_set).to eq(['apples', 'oranges'].to_set) end @@ -81,7 +83,7 @@ describe ProfilesController, :type => :controller do :tags => ',#apples,#oranges,', :profile => {:tag_string => '#pears'} } - put :update, params + put :update, params: params expect(eve.person(true).profile.tag_list.to_set).to eq(['apples', 'oranges', 'pears'].to_set) end @@ -90,7 +92,7 @@ describe ProfilesController, :type => :controller do :tags => ',#apples,#oranges,', :profile => {:tag_string => 'bananas'} } - put :update, params + put :update, params: params expect(eve.person(true).profile.tag_list.to_set).to eq(['apples', 'oranges', 'bananas'].to_set) end @@ -102,7 +104,7 @@ describe ProfilesController, :type => :controller do :month => '02', :day => '28' } } } - put :update, params + put :update, params: params expect(eve.person(true).profile.birthday.year).to eq(2001) expect(eve.person(true).profile.birthday.month).to eq(2) expect(eve.person(true).profile.birthday.day).to eq(28) @@ -116,7 +118,7 @@ describe ProfilesController, :type => :controller do :month => '02', :day => '31' } } } - put :update, params + put :update, params: params expect(flash[:error]).not_to be_blank end @@ -134,7 +136,7 @@ describe ProfilesController, :type => :controller do it "doesn't overwrite the profile photo when an empty string is passed in" do image_url = eve.person.profile.image_url - put :update, @params + put :update, params: @params expect(Person.find(eve.person.id).profile.image_url).to eq(image_url) end @@ -150,12 +152,12 @@ describe ProfilesController, :type => :controller do it 'person_id' do person = eve.person profile = person.profile - put :update, @profile_params + put :update, params: @profile_params expect(profile.reload.person_id).to eq(person.id) end it 'diaspora handle' do - put :update, @profile_params + put :update, params: @profile_params expect(Person.find(eve.person.id).profile[:diaspora_handle]).not_to eq('abc@a.com') end end diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index d39edb683624ddda88e7dcfd31fabcbac60e359d..91cf4603d3cca464fece8d786b0fdf170924f1c5 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -30,19 +30,19 @@ describe RegistrationsController, type: :controller do end it "redirects #create to the login page" do - post :create, valid_params + post :create, params: valid_params expect(flash[:error]).to eq(I18n.t("registrations.closed")) expect(response).to redirect_to new_user_session_path end it "does not redirect if there is a valid invite token" do code = InvitationCode.create(user: bob) - get :new, invite: {token: code.token} + get :new, params: {invite: {token: code.token}} expect(response).not_to be_redirect end it "does redirect if there is an invalid invite token" do - get :new, invite: {token: "fssdfsd"} + get :new, params: {invite: {token: "fssdfsd"}} expect(response).to redirect_to new_user_session_path end @@ -50,7 +50,7 @@ describe RegistrationsController, type: :controller do code = InvitationCode.create(user: bob) code.update_attributes(count: 0) - get :new, invite: {token: code.token} + get :new, params: {invite: {token: code.token}} expect(response).to redirect_to new_user_session_path end @@ -58,7 +58,7 @@ describe RegistrationsController, type: :controller do code = InvitationCode.create(user: bob) AppConfig.settings.invitations.open = false - get :new, invite: {token: code.token} + get :new, params: {invite: {token: code.token}} expect(response).to redirect_to new_user_session_path end @@ -68,7 +68,7 @@ describe RegistrationsController, type: :controller do code = InvitationCode.create(user: bob) code.update_attributes(count: 0) - get :new, invite: {token: code.token} + get :new, params: {invite: {token: code.token}} expect(response).not_to be_redirect end end @@ -79,22 +79,22 @@ describe RegistrationsController, type: :controller do context "with valid parameters" do it "creates a user" do expect { - get :create, valid_params + get :create, params: valid_params }.to change(User, :count).by(1) end it "assigns @user" do - get :create, valid_params + get :create, params: valid_params expect(assigns(:user)).to be_truthy end it "sets the flash" do - get :create, valid_params + get :create, params: valid_params expect(flash[:notice]).not_to be_blank end it "redirects to the home path" do - get :create, valid_params + get :create, params: valid_params expect(response).to be_redirect expect(response.location).to match(/^#{getting_started_url}$/) end @@ -106,7 +106,7 @@ describe RegistrationsController, type: :controller do code = InvitationCode.create(user: bob) expect { - get :create, valid_params.merge(invite: {token: code.token}) + get :create, params: valid_params.merge(invite: {token: code.token}) }.to change { code.reload.count }.by(-1) end @@ -114,14 +114,14 @@ describe RegistrationsController, type: :controller do code = InvitationCode.create(user: bob) expect { - get :create, valid_params.merge(invite: {token: code.token}) + get :create, params: valid_params.merge(invite: {token: code.token}) }.not_to change { code.reload.count } end it "links inviter with the user" do code = InvitationCode.create(user: bob) - post :create, valid_params.merge(invite: {token: code.token}) + post :create, params: valid_params.merge(invite: {token: code.token}) expect(User.find_by(username: "jdoe").invited_by).to eq(bob) end @@ -132,20 +132,20 @@ describe RegistrationsController, type: :controller do let(:invalid_params) { valid_params.deep_merge(user: {password_confirmation: "baddword"}) } it "does not create a user" do - expect { get :create, invalid_params }.not_to change(User, :count) + expect { get :create, params: invalid_params }.not_to change(User, :count) end it "does not create a person" do - expect { get :create, invalid_params }.not_to change(Person, :count) + expect { get :create, params: invalid_params }.not_to change(Person, :count) end it "assigns @user" do - get :create, invalid_params + get :create, params: invalid_params expect(assigns(:user)).not_to be_nil end it "sets the flash error" do - get :create, invalid_params + get :create, params: invalid_params expect(flash[:error]).not_to be_blank end @@ -155,17 +155,17 @@ describe RegistrationsController, type: :controller do code = InvitationCode.create(user: bob) expect { - get :create, invalid_params.merge(invite: {token: code.token}) + get :create, params: invalid_params.merge(invite: {token: code.token}) }.not_to change { code.reload.count } end it "renders new" do - get :create, invalid_params + get :create, params: invalid_params expect(response).to render_template("registrations/new") end it "keeps invalid params in form" do - get :create, invalid_params + get :create, params: invalid_params expect(response.body).to match /jdoe@example.com/m end end diff --git a/spec/controllers/report_controller_spec.rb b/spec/controllers/report_controller_spec.rb index bb049243cec1a891bc14ea4ae1a7aff9e2f21171..176a1d4f85f0b9bed70723bb8d9fedbed34a83b2 100644 --- a/spec/controllers/report_controller_spec.rb +++ b/spec/controllers/report_controller_spec.rb @@ -46,14 +46,14 @@ describe ReportController, type: :controller do context "report offensive post" do it "succeeds" do - put :create, report: {item_id: @message.id, item_type: "Post", text: "offensive content"} + put :create, params: {report: {item_id: @message.id, item_type: "Post", text: "offensive content"}} expect(response.status).to eq(200) expect(Report.exists?(item_id: @message.id, item_type: "Post")).to be true end end context "report offensive comment" do it "succeeds" do - put :create, report: {item_id: @comment.id, item_type: "Comment", text: "offensive content"} + put :create, params: {report: {item_id: @comment.id, item_type: "Comment", text: "offensive content"}} expect(response.status).to eq(200) expect(Report.exists?(item_id: @comment.id, item_type: "Comment")).to be true end @@ -63,14 +63,14 @@ describe ReportController, type: :controller do describe "#update" do context "mark post report as user" do it "is behind redirect_unless_admin_or_moderator" do - put :update, id: @message.id, type: "post" + put :update, params: {id: @message.id, type: "post"} expect(response).to redirect_to stream_path expect(Report.where(reviewed: false, item_id: @message.id, item_type: "Post")).to be_truthy end end context "mark comment report as user" do it "is behind redirect_unless_admin_or_moderator" do - put :update, id: @comment.id, type: "comment" + put :update, params: {id: @comment.id, type: "comment"} expect(response).to redirect_to stream_path expect(Report.where(reviewed: false, item_id: @comment.id, item_type: "Comment")).to be_truthy end @@ -81,7 +81,7 @@ describe ReportController, type: :controller do Role.add_admin(alice.person) end it "succeeds" do - put :update, id: @message.id, type: "post" + put :update, params: {id: @message.id, type: "post"} expect(response.status).to eq(302) expect(Report.where(reviewed: true, item_id: @message.id, item_type: "Post")).to be_truthy end @@ -91,7 +91,7 @@ describe ReportController, type: :controller do Role.add_admin(alice.person) end it "succeeds" do - put :update, id: @comment.id, type: "comment" + put :update, params: {id: @comment.id, type: "comment"} expect(response.status).to eq(302) expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "Comment")).to be_truthy end @@ -103,7 +103,7 @@ describe ReportController, type: :controller do end it "succeeds" do - put :update, id: @message.id, type: "post" + put :update, params: {id: @message.id, type: "post"} expect(response.status).to eq(302) expect(Report.where(reviewed: true, item_id: @message.id, item_type: "Post")).to be_truthy end @@ -114,7 +114,7 @@ describe ReportController, type: :controller do Role.add_moderator(alice.person) end it "succeeds" do - put :update, id: @comment.id, type: "comment" + put :update, params: {id: @comment.id, type: "comment"} expect(response.status).to eq(302) expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "Comment")).to be_truthy end @@ -124,14 +124,14 @@ describe ReportController, type: :controller do describe "#destroy" do context "destroy post as user" do it "is behind redirect_unless_admin_or_moderator" do - delete :destroy, id: @message.id, type: "post" + delete :destroy, params: {id: @message.id, type: "post"} expect(response).to redirect_to stream_path expect(Report.where(reviewed: false, item_id: @message.id, item_type: "Post")).to be_truthy end end context "destroy comment as user" do it "is behind redirect_unless_admin_or_moderator" do - delete :destroy, id: @comment.id, type: "comment" + delete :destroy, params: {id: @comment.id, type: "comment"} expect(response).to redirect_to stream_path expect(Report.where(reviewed: false, item_id: @comment.id, item_type: "Comment")).to be_truthy end @@ -142,7 +142,7 @@ describe ReportController, type: :controller do Role.add_admin(alice.person) end it "succeeds" do - delete :destroy, id: @message.id, type: "post" + delete :destroy, params: {id: @message.id, type: "post"} expect(response.status).to eq(302) expect(Report.where(reviewed: true, item_id: @message.id, item_type: "Post")).to be_truthy end @@ -152,7 +152,7 @@ describe ReportController, type: :controller do Role.add_admin(alice.person) end it "succeeds" do - delete :destroy, id: @comment.id, type: "comment" + delete :destroy, params: {id: @comment.id, type: "comment"} expect(response.status).to eq(302) expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "Comment")).to be_truthy end @@ -163,7 +163,7 @@ describe ReportController, type: :controller do Role.add_moderator(alice.person) end it "succeeds" do - delete :destroy, id: @message.id, type: "post" + delete :destroy, params: {id: @message.id, type: "post"} expect(response.status).to eq(302) expect(Report.where(reviewed: true, item_id: @message.id, item_type: "Post")).to be_truthy end @@ -173,7 +173,7 @@ describe ReportController, type: :controller do Role.add_moderator(alice.person) end it "succeeds" do - delete :destroy, id: @comment.id, type: "comment" + delete :destroy, params: {id: @comment.id, type: "comment"} expect(response.status).to eq(302) expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "Comment")).to be_truthy end diff --git a/spec/controllers/reshares_controller_spec.rb b/spec/controllers/reshares_controller_spec.rb index 38a65b94e91b4f994639ddd36f3459e0a386f24c..4682baa2345267318462b1a894adb0204b82fea6 100644 --- a/spec/controllers/reshares_controller_spec.rb +++ b/spec/controllers/reshares_controller_spec.rb @@ -1,7 +1,7 @@ describe ResharesController, :type => :controller do describe '#create' do let(:post_request!) { - post :create, :format => :json, :root_guid => @post_guid + post :create, params: {root_guid: @post_guid}, format: :json } before do @@ -74,13 +74,13 @@ describe ResharesController, :type => :controller do it "returns a 404 for a post not visible to the user" do sign_in(eve, scope: :user) expect { - get :index, post_id: @post.id, format: :json + get :index, params: {post_id: @post.id}, format: :json }.to raise_error(ActiveRecord::RecordNotFound) end it "returns an empty array for a post visible to the user" do sign_in(bob, scope: :user) - get :index, post_id: @post.id, format: :json + get :index, params: {post_id: @post.id}, format: :json expect(JSON.parse(response.body)).to eq([]) end end @@ -93,12 +93,12 @@ describe ResharesController, :type => :controller do it "returns an array of reshares for a post" do bob.reshare!(@post) - get :index, post_id: @post.id, format: :json + get :index, params: {post_id: @post.id}, format: :json expect(JSON.parse(response.body).map {|h| h["id"] }).to eq(@post.reshares.map(&:id)) end it "returns an empty array for a post with no reshares" do - get :index, post_id: @post.id, format: :json + get :index, params: {post_id: @post.id}, format: :json expect(JSON.parse(response.body)).to eq([]) end end diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index ab90b253b7806b96fed43f68192bcd0fa3a6e06a..655cb86d4701eae02c380592d1dbd83286347c36 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -7,7 +7,7 @@ describe SearchController, :type => :controller do describe 'query is a person' do it 'goes to people index page' do - get :search, :q => 'eugene' + get :search, params: {q: "eugene"} expect(response).to be_redirect end end @@ -15,17 +15,17 @@ describe SearchController, :type => :controller do describe 'query is a tag' do it 'goes to a tag page' do - get :search, :q => '#cats' + get :search, params: {q: "#cats"} expect(response).to redirect_to(tag_path('cats')) end it 'removes dots from the query' do - get :search, :q => '#cat.s' + get :search, params: {q: "#cat.s"} expect(response).to redirect_to(tag_path('cats')) end it 'stay on the page if you search for the empty hash' do - get :search, :q => '#' + get :search, params: {q: "#"} expect(flash[:error]).to be_present end end diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 75cff3391ffbdd6bf282d6fafca5779cbe44d1e6..9ad8e36aa71728a786fc35c449220af09522da9f 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -35,12 +35,12 @@ describe ServicesController, :type => :controller do it 'creates a new service and associates it with the current user' do expect { - post :create, :provider => 'facebook' + post :create, params: {provider: "facebook"} }.to change(user.services, :count).by(1) end it 'saves the provider' do - post :create, :provider => 'facebook' + post :create, params: {provider: "facebook"} expect(user.reload.services.first.class.name).to eq("Services::Facebook") end @@ -49,7 +49,7 @@ describe ServicesController, :type => :controller do it "imports the profile photo from the service" do expect(Workers::FetchProfilePhoto).to receive(:perform_async) - post :create, :provider => 'facebook' + post :create, params: {provider: "facebook"} end end @@ -58,12 +58,12 @@ describe ServicesController, :type => :controller do it 'doesnt create a new service' do service_count = Service.count - post :create, :provider => 'twitter' + post :create, params: {provider: "twitter"} expect(Service.count).to eq(service_count) end it 'flashes an already_authorized error with the diaspora handle for the user' do - post :create, :provider => 'twitter' + post :create, params: {provider: "twitter"} expect(flash[:error].include?(user.profile.diaspora_handle)).to be true expect(flash[:error].include?( 'already authorized' )).to be true end @@ -84,12 +84,12 @@ describe ServicesController, :type => :controller do it 'doesnt create a new service' do service_count = Service.count - post :create, :provider => 'twitter' + post :create, params: {provider: "twitter"} expect(Service.count).to eq(service_count) end it 'flashes an read-only access error' do - post :create, :provider => 'twitter' + post :create, params: {provider: "twitter"} expect(flash[:error].include?( 'Access level is read-only' )).to be true end end @@ -103,7 +103,7 @@ describe ServicesController, :type => :controller do it "doesn't break when twitter-specific extras aren't available in omniauth hash" do expect { - post :create, :provider => 'facebook' + post :create, params: {provider: "facebook"} }.to change(user.services, :count).by(1) end end @@ -121,7 +121,7 @@ describe ServicesController, :type => :controller do expect(Workers::FetchProfilePhoto).not_to receive(:perform_async) - post :create, :provider => 'twitter' + post :create, params: {provider: "twitter"} end it 'queues a job to save user photo if the photo does not exist' do @@ -129,7 +129,7 @@ describe ServicesController, :type => :controller do expect(Workers::FetchProfilePhoto).to receive(:perform_async).with(user.id, anything(), "https://service.com/fallback_lowres.jpg") - post :create, :provider => 'twitter' + post :create, params: {provider: "twitter"} end end end @@ -141,7 +141,7 @@ describe ServicesController, :type => :controller do it 'destroys a service selected by id' do expect{ - delete :destroy, :id => @service1.id + delete :destroy, params: {id: @service1.id} }.to change(user.services, :count).by(-1) end end diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index 55ae17baed77ad1d543d7f2056c48a8bba603568..69bbf510c67e5a53c0a2fcea30b28e9cda615244 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -15,14 +15,14 @@ describe SessionsController, type: :controller do describe "#create" do it "redirects to /stream for a non-mobile user" do - post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}} + post :create, params: {user: {remember_me: "0", username: @user.username, password: "evankorth"}} expect(response).to be_redirect expect(response.location).to match /^#{stream_url}\??$/ end it "redirects to /stream for a mobile user" do request.headers["X_MOBILE_DEVICE"] = true - post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}} + post :create, params: {user: {remember_me: "0", username: @user.username, password: "evankorth"}} expect(response).to be_redirect expect(response.location).to match /^#{stream_url}\??$/ end diff --git a/spec/controllers/share_visibilities_controller_spec.rb b/spec/controllers/share_visibilities_controller_spec.rb index 30c0151e976f7ca9786cc2b0c697b1d9c6a73ec6..f70a50ea3396fd5c7c855be6bc70f862611d0513 100644 --- a/spec/controllers/share_visibilities_controller_spec.rb +++ b/spec/controllers/share_visibilities_controller_spec.rb @@ -14,13 +14,13 @@ describe ShareVisibilitiesController, :type => :controller do end it 'succeeds' do - put :update, :format => :js, :id => 42, :post_id => @status.id + put :update, params: {id: 42, post_id: @status.id}, format: :js expect(response).to be_success end it 'it calls toggle_hidden_shareable' do expect(@controller.current_user).to receive(:toggle_hidden_shareable).with(an_instance_of(StatusMessage)) - put :update, :format => :js, :id => 42, :post_id => @status.id + put :update, params: {id: 42, post_id: @status.id}, format: :js end end @@ -31,14 +31,14 @@ describe ShareVisibilitiesController, :type => :controller do it "raises an error" do expect { - put :update, format: :js, id: 42, post_id: @status.id + put :update, params: {id: 42, post_id: @status.id}, format: :js }.to raise_error ActiveRecord::RecordNotFound end it "it doesn't call toggle_hidden_shareable" do expect(@controller.current_user).not_to receive(:toggle_hidden_shareable).with(an_instance_of(StatusMessage)) begin - put :update, format: :js, id: 42, post_id: @status.id + put :update, params: {id: 42, post_id: @status.id}, format: :js rescue ActiveRecord::RecordNotFound end end diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index 5d2dcd9ae36a644105cdcd8fc4b89016c6a6fabf..8b99c04c2b6b934b578c984aa33daee7db574105 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -27,16 +27,18 @@ describe StatusMessagesController, :type => :controller do end it 'accepts get params' do - get :bookmarklet, { url: 'https://www.youtube.com/watch?v=0Bmhjf0rKe8', - title: 'Surprised Kitty', - notes: 'cute kitty' } + get :bookmarklet, params: { + url: "https://www.youtube.com/watch?v=0Bmhjf0rKe8", + title: "Surprised Kitty", + notes: "cute kitty" + } expect(response).to be_success end end describe '#new' do it 'succeeds' do - get :new, :person_id => bob.person.id + get :new, params: {person_id: bob.person.id} expect(response).to be_success end @@ -56,30 +58,30 @@ describe StatusMessagesController, :type => :controller do } it 'creates with valid json' do - post :create, status_message_hash.merge(:format => 'json') + post :create, params: status_message_hash, format: :json expect(response.status).to eq(201) end it 'creates with invalid json' do - post :create, status_message_hash.merge(:status_message => { :text => "0123456789" * 7000 }, :format => 'json') + post :create, params: status_message_hash.merge(status_message: {text: "0123456789" * 7000}), format: :json expect(response.status).to eq(403) end it 'creates with valid mobile' do - post :create, status_message_hash.merge(:format => 'mobile') + post :create, params: status_message_hash, format: :mobile expect(response.status).to eq(302) expect(response).to be_redirect end it 'creates with invalid mobile' do - post :create, status_message_hash.merge(:status_message => { :text => "0123456789" * 7000 }, :format => 'mobile') + post :create, params: status_message_hash.merge(status_message: {text: "0123456789" * 7000}), format: :mobile expect(response.status).to eq(302) expect(response).to be_redirect end it 'removes getting started from new users' do expect(@controller).to receive(:remove_getting_started) - post :create, status_message_hash + post :create, params: status_message_hash end context "with aspect_ids" do @@ -88,43 +90,43 @@ describe StatusMessagesController, :type => :controller do end it "takes one aspect as array in aspect_ids" do - post :create, status_message_hash - expect(response.status).to eq(302) + post :create, params: status_message_hash, format: :json + expect(response.status).to eq(201) status_message = StatusMessage.find_by_text(text) - expect(status_message.aspect_visibilities.map(&:aspect)).to eq([@aspect1]) + expect(status_message.aspect_visibilities.map(&:aspect)).to eq([@aspect1]), format: :json end it "takes one aspect as string in aspect_ids" do - post :create, status_message_hash.merge(aspect_ids: @aspect1.id.to_s) - expect(response.status).to eq(302) + post :create, params: status_message_hash.merge(aspect_ids: @aspect1.id.to_s), format: :json + expect(response.status).to eq(201) status_message = StatusMessage.find_by_text(text) expect(status_message.aspect_visibilities.map(&:aspect)).to eq([@aspect1]) end it "takes public as array in aspect_ids" do - post :create, status_message_hash.merge(aspect_ids: ["public"]) - expect(response.status).to eq(302) + post :create, params: status_message_hash.merge(aspect_ids: ["public"]), format: :json + expect(response.status).to eq(201) status_message = StatusMessage.find_by_text(text) expect(status_message.public).to be_truthy end it "takes public as string in aspect_ids" do - post :create, status_message_hash.merge(aspect_ids: "public") - expect(response.status).to eq(302) + post :create, params: status_message_hash.merge(aspect_ids: "public"), format: :json + expect(response.status).to eq(201) status_message = StatusMessage.find_by_text(text) expect(status_message.public).to be_truthy end it "takes all_aspects as array in aspect_ids" do - post :create, status_message_hash.merge(aspect_ids: ["all_aspects"]) - expect(response.status).to eq(302) + post :create, params: status_message_hash.merge(aspect_ids: ["all_aspects"]), format: :json + expect(response.status).to eq(201) status_message = StatusMessage.find_by_text(text) expect(status_message.aspect_visibilities.map(&:aspect)).to match_array([@aspect1, @aspect2]) end it "takes all_aspects as string in aspect_ids" do - post :create, status_message_hash.merge(aspect_ids: "all_aspects") - expect(response.status).to eq(302) + post :create, params: status_message_hash.merge(aspect_ids: "all_aspects"), format: :json + expect(response.status).to eq(201) status_message = StatusMessage.find_by_text(text) expect(status_message.aspect_visibilities.map(&:aspect)).to match_array([@aspect1, @aspect2]) end @@ -137,7 +139,7 @@ describe StatusMessagesController, :type => :controller do status_message_hash[:services] = ['facebook'] service_types = Service.titles(status_message_hash[:services]) expect(alice).to receive(:dispatch_post).with(anything(), hash_including(:service_types => service_types)) - post :create, status_message_hash + post :create, params: status_message_hash end it "works if services is a string" do @@ -145,12 +147,12 @@ describe StatusMessagesController, :type => :controller do alice.services << s1 status_message_hash[:services] = "facebook" expect(alice).to receive(:dispatch_post).with(anything(), hash_including(:service_types => ["Services::Facebook"])) - post :create, status_message_hash + post :create, params: status_message_hash end it "doesn't overwrite author_id" do status_message_hash[:status_message][:author_id] = bob.person.id - post :create, status_message_hash + post :create, params: status_message_hash new_message = StatusMessage.find_by_text(text) expect(new_message.author_id).to eq(alice.person.id) end @@ -158,7 +160,7 @@ describe StatusMessagesController, :type => :controller do it "doesn't overwrite id" do old_status_message = alice.post(:status_message, :text => "hello", :to => @aspect1.id) status_message_hash[:status_message][:id] = old_status_message.id - post :create, status_message_hash + post :create, params: status_message_hash expect(old_status_message.reload.text).to eq('hello') end @@ -166,18 +168,18 @@ describe StatusMessagesController, :type => :controller do expect(alice).to receive(:dispatch_post) {|post, _opts| expect(post.subscribers).to eq([bob.person]) } - post :create, status_message_hash + post :create, params: status_message_hash end it 'respsects provider_display_name' do status_message_hash.merge!(:aspect_ids => ['public']) status_message_hash[:status_message].merge!(:provider_display_name => "mobile") - post :create, status_message_hash + post :create, params: status_message_hash expect(StatusMessage.first.provider_display_name).to eq('mobile') end it "has no participation" do - post :create, status_message_hash + post :create, params: status_message_hash new_message = StatusMessage.find_by_text(text) expect(new_message.participations.count).to eq(0) end @@ -196,19 +198,19 @@ describe StatusMessagesController, :type => :controller do it "will post a photo without text" do @hash.delete :text - post :create, @hash - expect(response).to be_redirect + post :create, params: @hash, format: :json + expect(response.status).to eq(201) end it "attaches all referenced photos" do - post :create, @hash + post :create, params: @hash, format: :json status_message = StatusMessage.find_by_text(text) expect(status_message.photos.map(&:id)).to match_array([@photo1, @photo2].map(&:id)) end it "sets the pending bit of referenced photos" do inlined_jobs do - post :create, @hash + post :create, params: @hash, format: :json end expect(@photo1.reload.pending).to be false diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb index 3b49bccbc2a5585851e913ae553228685fab3944..b62adc5b000263f5993d5dd16176ce54975b6eca 100644 --- a/spec/controllers/tags_controller_spec.rb +++ b/spec/controllers/tags_controller_spec.rb @@ -12,13 +12,13 @@ describe TagsController, :type => :controller do end it 'responds with json' do - get :index, :q => "ra", :format => 'json' + get :index, params: {q: "ra"}, format: :json #parse json expect(response.body).to include("#rad") end it 'requires at least two characters' do - get :index, :q => "c", :format => 'json' + get :index, params: {q: "c"}, format: :json expect(response.body).not_to include("#cats") end @@ -28,7 +28,7 @@ describe TagsController, :type => :controller do end it 'does not allow json requestors to party' do - get :index, :format => :json + get :index, format: :json expect(response.status).to eq(422) end end @@ -40,7 +40,7 @@ describe TagsController, :type => :controller do end it 'redirect to the downcase tag uri' do - get :show, :name => 'DiasporaRocks!' + get :show, params: {name: "DiasporaRocks!"} expect(response).to redirect_to(:action => :show, :name => 'diasporarocks!') end end @@ -53,7 +53,7 @@ describe TagsController, :type => :controller do end it 'includes the tagged user' do - get :show, :name => 'cats' + get :show, params: {name: "cats"} expect(response.body).to include(bob.diaspora_handle) end end @@ -69,40 +69,40 @@ describe TagsController, :type => :controller do end it 'assigns a Stream::Tag object with the current_user' do - get :show, :name => 'yes' + get :show, params: {name: "yes"} expect(assigns[:stream].user).to eq(alice) end it 'succeeds' do - get :show, :name => 'hellyes' + get :show, params: {name: "hellyes"} expect(response.status).to eq(200) end it 'includes the tagged post' do - get :show, :name => 'foo' + get :show, params: {name: "foo"} expect(assigns[:stream].posts.first.text).to include("tagged post") end it 'includes comments of the tagged post' do alice.comment!(@post, "comment on a tagged post") - get :show, :name => 'foo', :format => 'json' + get :show, params: {name: "foo"}, format: :json expect(response.body).to include("comment on a tagged post") end end context "not signed in" do it 'assigns a Stream::Tag object with no user' do - get :show, :name => 'yes' + get :show, params: {name: "yes"} expect(assigns[:stream].user).to be_nil end it 'succeeds' do - get :show, :name => 'hellyes' + get :show, params: {name: "hellyes"} expect(response.status).to eq(200) end it 'succeeds with mobile' do - get :show, :name => 'foo', :format => :mobile + get :show, params: {name: "foo"}, format: :mobile expect(response).to be_success end @@ -113,7 +113,7 @@ describe TagsController, :type => :controller do public: true, created_at: @post.created_at - 1.day ) - get :show, name: "what", max_time: @post.created_at, format: :json + get :show, params: {name: "what", max_time: @post.created_at.to_i}, format: :json expect(JSON.parse(response.body).size).to be(1) expect(JSON.parse(response.body).first["guid"]).to eq(post2.guid) end @@ -122,7 +122,7 @@ describe TagsController, :type => :controller do it "includes the correct meta tags" do tag_url = tag_url "yes", host: AppConfig.pod_uri.host, port: AppConfig.pod_uri.port - get :show, name: "yes" + get :show, params: {name: "yes"} expect(response.body).to include('<meta name="keywords" content="yes" />') expect(response.body).to include( diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index b68b96a95e076a1b8e3c39f660a8a69ea0cc5d09..e3ef6a78585f438dca5731d71babf5e146aa0443 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -58,26 +58,26 @@ describe UsersController, :type => :controller do end it "contains the text" do - get :public, username: @user.username, format: :atom + get :public, params: {username: @user.username}, format: :atom doc = Nokogiri::XML(response.body) expect(doc.css("entry content")[0].content).to eq(@sm.message.markdownified(disable_hovercards: true)) end it "contains the title" do - get :public, username: @user.username, format: :atom + get :public, params: {username: @user.username}, format: :atom doc = Nokogiri::XML(response.body) expect(doc.css("entry title")[0].content).to eq(post_page_title(@sm)) end it "contains the author" do - get :public, username: @user.username, format: :atom + get :public, params: {username: @user.username}, format: :atom doc = Nokogiri::XML(response.body) expect(doc.css("entry author name")[0].content).to eq(@sm.author_name) end it "contains the original author for reshares" do FactoryGirl.create(:reshare, root: @sm, author: bob.person) - get :public, username: bob.username, format: :atom + get :public, params: {username: bob.username}, format: :atom doc = Nokogiri::XML(response.body) expect(doc.css("entry author name")[0].content).to eq(@sm.author_name) end @@ -85,7 +85,7 @@ describe UsersController, :type => :controller do it 'includes reshares in the atom feed' do reshare = FactoryGirl.create(:reshare, :author => @user.person) - get :public, :username => @user.username, :format => :atom + get :public, params: {username: @user.username}, format: :atom expect(response.body).to include reshare.root.text end @@ -93,17 +93,17 @@ describe UsersController, :type => :controller do post = FactoryGirl.create(:status_message, :public => true); reshare = FactoryGirl.create(:reshare, :root => post, :author => @user.person) post.delete - get :public, :username => @user.username, :format => :atom + get :public, params: {username: @user.username}, format: :atom expect(response.code).to eq('200') end it 'redirects to a profile page if html is requested' do - get :public, :username => @user.username + get :public, params: {username: @user.username} expect(response).to be_redirect end it 'redirects to a profile page if mobile is requested' do - get :public, :username => @user.username, :format => :mobile + get :public, params: {username: @user.username}, format: :mobile expect(response).to be_redirect end end @@ -116,12 +116,12 @@ describe UsersController, :type => :controller do it "doesn't overwrite random attributes" do expect { - put :update, @params + put :update, params: @params }.not_to change(@user, :diaspora_handle) end it 'renders the user edit page' do - put :update, @params + put :update, params: @params expect(response).to render_template('edit') end @@ -139,7 +139,7 @@ describe UsersController, :type => :controller do it "uses devise's update with password" do expect(@user).to receive(:update_with_password).with(hash_including(password_params)) allow(@controller).to receive(:current_user).and_return(@user) - put :update, params + put :update, params: params end end @@ -148,9 +148,7 @@ describe UsersController, :type => :controller do old_language = 'en' @user.language = old_language @user.save - put(:update, :id => @user.id, :user => - { :language => "fr"} - ) + put :update, params: {id: @user.id, user: {language: "fr"}} @user.reload expect(@user.language).not_to eq(old_language) end @@ -161,7 +159,7 @@ describe UsersController, :type => :controller do old_color_theme = "original" @user.color_theme = old_color_theme @user.save - put(:update, id: @user.id, user: {color_theme: "dark_green"}) + put :update, params: {id: @user.id, user: {color_theme: "dark_green"}} @user.reload expect(@user.color_theme).not_to eq(old_color_theme) end @@ -170,43 +168,43 @@ describe UsersController, :type => :controller do describe 'email' do it 'disallow the user to change his new (unconfirmed) mail when it is the same as the old' do @user.email = "my@newemail.com" - put(:update, :id => @user.id, :user => { :email => "my@newemail.com"}) + put :update, params: {id: @user.id, user: {email: "my@newemail.com"}} @user.reload expect(@user.unconfirmed_email).to eql(nil) end it 'allow the user to change his (unconfirmed) email' do - put(:update, :id => @user.id, :user => { :email => "my@newemail.com"}) + put :update, params: {id: @user.id, user: {email: "my@newemail.com"}} @user.reload expect(@user.unconfirmed_email).to eql("my@newemail.com") end it 'informs the user about success' do - put(:update, :id => @user.id, :user => { :email => "my@newemail.com"}) + put :update, params: {id: @user.id, user: {email: "my@newemail.com"}} expect(request.flash[:notice]).to eql(I18n.t('users.update.unconfirmed_email_changed')) expect(request.flash[:error]).to be_blank end it 'informs the user about failure' do - put(:update, id: @user.id, user: {email: "mynewemailcom"}) + put :update, params: {id: @user.id, user: {email: "mynewemailcom"}} expect(request.flash[:error]).to eql(I18n.t('users.update.unconfirmed_email_not_changed')) expect(request.flash[:notice]).to be_blank end it 'allow the user to change his (unconfirmed) email to blank (= abort confirmation)' do - put(:update, :id => @user.id, :user => { :email => ""}) + put :update, params: {id: @user.id, user: {email: ""}} @user.reload expect(@user.unconfirmed_email).to eql(nil) end it 'sends out activation email on success' do expect(Workers::Mail::ConfirmEmail).to receive(:perform_async).with(@user.id).once - put(:update, :id => @user.id, :user => { :email => "my@newemail.com"}) + put :update, params: {id: @user.id, user: {email: "my@newemail.com"}} end it "saves unconfirmed_email when podmail is disabled" do AppConfig.mail.enable = false - put(:update, id: @user.id, user: {email: "my@newemail.com"}) + put :update, params: {id: @user.id, user: {email: "my@newemail.com"}} @user.reload expect(@user.email).to eql("my@newemail.com") end @@ -218,7 +216,7 @@ describe UsersController, :type => :controller do it "lets the user turn off mail" do par = {id: @user.id, user: {email_preferences: {email_type => "true"}}} expect { - put :update, par + put :update, params: par }.to change(@user.user_preferences, :count).by(1) end @@ -226,7 +224,7 @@ describe UsersController, :type => :controller do @user.user_preferences.create(email_type: email_type) par = {id: @user.id, user: {email_preferences: {email_type => "false"}}} expect { - put :update, par + put :update, params: par }.to change(@user.user_preferences, :count).by(-1) end end @@ -235,7 +233,7 @@ describe UsersController, :type => :controller do describe 'getting started' do it 'can be reenabled' do - put :update, user: {getting_started: true} + put :update, params: {user: {getting_started: true}} expect(@user.reload.getting_started?).to be true end end @@ -250,32 +248,32 @@ describe UsersController, :type => :controller do describe '#edit' do it "returns a 200" do - get 'edit', :id => @user.id + get :edit, params: {id: @user.id} expect(response.status).to eq(200) end it 'displays community spotlight checkbox' do AppConfig.settings.community_spotlight.enable = true - get 'edit', :id => @user.id + get :edit, params: {id: @user.id} expect(response.body).to include('input name="user[show_community_spotlight_in_stream]"') end it 'hides community spotlight checkbox' do AppConfig.settings.community_spotlight = false - get 'edit', :id => @user.id + get :edit, params: {id: @user.id} expect(response.body).not_to include('input name="user[show_community_spotlight_in_stream]"') end it 'set @email_pref to false when there is a user pref' do @user.user_preferences.create(:email_type => 'mentioned') - get 'edit', :id => @user.id + get :edit, params: {id: @user.id} expect(assigns[:email_prefs]['mentioned']).to be false end it "does not allow token auth" do sign_out :user bob.reset_authentication_token! - get :edit, :auth_token => bob.authentication_token + get :edit, params: {auth_token: bob.authentication_token} expect(response).to redirect_to new_user_session_path end end @@ -283,17 +281,17 @@ describe UsersController, :type => :controller do describe '#destroy' do it 'does nothing if the password does not match' do expect(Workers::DeleteAccount).not_to receive(:perform_async) - delete :destroy, :user => { :current_password => "stuff" } + delete :destroy, params: {user: {current_password: "stuff"}} end it 'closes the account' do expect(alice).to receive(:close_account!) - delete :destroy, :user => { :current_password => "bluepin7" } + delete :destroy, params: {user: {current_password: "bluepin7"}} end it 'enqueues a delete job' do expect(Workers::DeleteAccount).to receive(:perform_async).with(anything) - delete :destroy, :user => { :current_password => "bluepin7" } + delete :destroy, params: {user: {current_password: "bluepin7"}} end end @@ -303,12 +301,12 @@ describe UsersController, :type => :controller do end it 'redirects to to the user edit page' do - get 'confirm_email', :token => @user.confirm_email_token + get :confirm_email, params: {token: @user.confirm_email_token} expect(response).to redirect_to edit_user_path end it 'confirms email' do - get 'confirm_email', :token => @user.confirm_email_token + get :confirm_email, params: {token: @user.confirm_email_token} @user.reload expect(@user.email).to eql('my@newemail.com') expect(request.flash[:notice]).to eql(I18n.t('users.confirm_email.email_confirmed', :email => 'my@newemail.com')) @@ -316,7 +314,7 @@ describe UsersController, :type => :controller do end it 'does NOT confirm email with wrong token' do - get 'confirm_email', :token => @user.confirm_email_token.reverse + get :confirm_email, params: {token: @user.confirm_email_token.reverse} @user.reload expect(@user.email).not_to eql('my@newemail.com') expect(request.flash[:error]).to eql(I18n.t('users.confirm_email.email_not_confirmed')) @@ -331,7 +329,7 @@ describe UsersController, :type => :controller do end it 'does not fail miserably on mobile' do - get :getting_started, :format => :mobile + get :getting_started, format: :mobile expect(response).to be_success end diff --git a/spec/integration/api/user_info_controller_spec.rb b/spec/integration/api/user_info_controller_spec.rb index eaff504593a4d0a107029e328e7b272a54c72fbe..2c692a1003a4b6a0174adb5f4b735cf4a2815d9d 100644 --- a/spec/integration/api/user_info_controller_spec.rb +++ b/spec/integration/api/user_info_controller_spec.rb @@ -5,7 +5,7 @@ describe Api::OpenidConnect::UserInfoController do describe "#show" do before do @user = auth_with_read_and_ppid.user - get api_openid_connect_user_info_path, access_token: access_token_with_read + get api_openid_connect_user_info_path, params: {access_token: access_token_with_read} end it "shows the info" do