Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect routes with functional tests #835

Merged
merged 24 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4e238af
Remove typo to fix spectra author link
Georjane Dec 20, 2021
97ac51f
Run mysql query to fix errors
Georjane Dec 20, 2021
d7746c1
Run yarn check to fix errors
Georjane Dec 20, 2021
70c7858
Check if tests are working
Georjane Dec 21, 2021
d91edb2
Try to break test to see if it fails
Georjane Dec 21, 2021
5ea172c
Add test to check for RSS on author profile
Georjane Dec 21, 2021
deffe05
Edit test to check for RSS on author profile
Georjane Dec 21, 2021
f505e55
Edit test to check for RSS on author profile
Georjane Dec 21, 2021
5e7b1fd
Add first to test to check for RSS on author profile
Georjane Dec 21, 2021
388f91f
Add first to test to check for RSS on author profile
Georjane Dec 21, 2021
820d1f2
Add first to test to check for RSS on author profile
Georjane Dec 21, 2021
58d6c43
Fix test
Georjane Dec 21, 2021
9fa1392
Fix test
Georjane Dec 21, 2021
28e568f
Update home_test.rb
Georjane Jan 6, 2022
ad1293d
Comment out test to check for merge conflicts
Georjane Jan 10, 2022
3eefc09
Remove gemfile.lock to fix merge conflict
Georjane Jan 10, 2022
87378fe
Add tests for get macros index
Georjane Jan 11, 2022
a7bce5f
Edit macros index method in controller
Georjane Jan 11, 2022
e8aea98
Add post create macro route
Georjane Jan 11, 2022
53cd9d2
Add html_safe to fix delete icon
Georjane Jan 11, 2022
02d1047
Remove codes coming from other PRs
Georjane Feb 8, 2022
4719995
Merge branch 'main' into add_tests_for_macros_controller
Georjane Feb 8, 2022
d6bc34d
Rerun yarn install
Georjane Feb 8, 2022
7751692
Remove spectrum controller from commit
Georjane Feb 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/controllers/macros_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

class MacrosController < ApplicationController
def index
@macros = Macro.find :all, order: 'id DESC'
# @macros = Macro.find :all, order: 'id DESC'
@macros = Macro.all.order(id: :desc)
end

def author
Expand All @@ -13,7 +14,7 @@ def author

def show
@user = User.find_by_login params[:author]
@macro = Macro.find_by_title params[:id], conditions: { user_id: @user.id }, order: 'id DESC'
@macro = Macro.find_by title: params[:id], conditions: { user_id: @user.id }, order: 'id DESC'
respond_to do |format|
format.html {}
format.js do
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/spectrums_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def create # rubocop:disable Metrics/AbcSize
@spectrum.extract_data if !params[:spectrum][:json] || params[:spectrum][:json].empty?

calibration_param = if params[:spectrum][:calibration_id] && !params[:is_calibration] && params[:spectrum][:calibration_id] != 'calibration' && params[:spectrum][:calibration_id] != 'undefined'
# @spectrum.clone_calibration(params[:spectrum][:calibration_id])
# @spectrum.clone_calibration(params[:spectrum][:calibration_id])
# instead, append params[:spectrum][:calibration_id] to "#addTag=calibrate:#{params[:spectrum][:calibration_id].to_i}"
"#addTag=calibrate:#{params[:spectrum][:calibration_id].to_i}"
else
Expand Down Expand Up @@ -545,4 +545,4 @@ def set_search
@user_sets = current_user.sets if logged_in?
render partial: 'spectrums/show/set_results', layout: false
end
end
end
2 changes: 1 addition & 1 deletion app/views/macros/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<p><a class="btn btn-small" href="mailto:[email protected]"><i class="fa fa-flag"></i> Report abuse</a>
<% if logged_in? && (current_user.id == @macro.user_id || current_user.role == "admin") %>
<%= link_to '<i class="fa fa-trash"></i> Delete', "/macros/delete/"[email protected]_s, :confirm => 'Are you sure?', :class => "btn btn-small" %>
<%= link_to '<i class="fa fa-trash"></i> Delete'.html_safe, "/macros/delete/"[email protected]_s, :confirm => 'Are you sure?', :class => "btn btn-small" %>
<a class="btn btn-small" href="/macro/edit/<%= @macro.id %>"><i class="fa fa-pencil"></i> Edit macro</a>
<% end %>

Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
get '/profile', to: 'users#show'
get '/profile/:id', to: 'users#show'

post '/macros/create' => 'macros#create'
get '/macro/edit/:id' => 'macros#edit'
get '/macro/update/:id' => 'macros#update'
get '/macro/:author/:id' => 'macros#show'
Expand Down
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
"name": "spectral-workbench",
"version": "1.0.0",
"private": "true",
"repository": "https://github.com/publiclab/spectral-workbench/",
"repository": {
"type": "git",
"url": "git+https://github.com/publiclab/spectral-workbench.git"
},
"author": "Public Lab contributors <[email protected]>",
"license": "GPL-3.0",
"dependencies": {
"ace-builds": "^1.4.14",
"adapterjs": "^0.15.5",
"bootstrap-css": "jozefizso/bower-bootstrap-css#~2.3.2",
"bootstrap": "^5.1.3",
"bootstrap-css": "github:jozefizso/bower-bootstrap-css#~2.3.2",
"bs-stepper": "^1.7.0",
"d3": "^3.5.4",
"flot": "~0.8.0-alpha",
Expand All @@ -28,5 +32,16 @@
},
"scripts": {
"postinstall": "node -e \"try { require('fs').symlinkSync(require('path').resolve('node_modules/@bower_components'), 'public/lib', 'junction') } catch (e) { }\""
},
"description": "Copyright Public Lab publiclab.org | spectralworkbench.org",
"bugs": {
"url": "https://github.com/publiclab/spectral-workbench/issues"
},
"homepage": "https://github.com/publiclab/spectral-workbench#readme",
"main": "index.js",
"directories": {
"doc": "doc",
"lib": "lib",
"test": "test"
}
}
10 changes: 10 additions & 0 deletions test/controllers/macros_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require 'test_helper'

class MacrosControllerTest < ActionController::TestCase
test 'should get macros index' do
get :index
assert_response :success
end
end
1 change: 1 addition & 0 deletions test/system/home_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ class HomeTest < ApplicationSystemTestCase
assert_selector('a.btn.btn-large.btn-primary', text: 'Begin capturing »')
end
end

end
63 changes: 34 additions & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ ansi-styles@^1.1.0:
integrity sha1-6uy/Zs1waIJ2Cy9GkVgrj1XXp94=

asn1@~0.2.3:
version "0.2.4"
resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.4.tgz#8d2475dfab553bb33e77b54e59e880bb8ce23136"
integrity sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==
version "0.2.6"
resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.6.tgz#0d3a7bb6e64e02a90c0303b31f292868ea09a08d"
integrity sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==
dependencies:
safer-buffer "~2.1.0"

Expand Down Expand Up @@ -145,10 +145,15 @@ [email protected]:
raw-body "1.1.6"
type-is "1.2.1"

bootstrap-css@jozefizso/bower-bootstrap-css#~2.3.2:
"bootstrap-css@github:jozefizso/bower-bootstrap-css#~2.3.2":
version "0.0.0"
resolved "https://codeload.github.com/jozefizso/bower-bootstrap-css/tar.gz/3ca4d051f9d391d56641f7f30c6c936f39944910"

bootstrap@^5.1.3:
version "5.1.3"
resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-5.1.3.tgz#ba081b0c130f810fa70900acbc1c6d3c28fa8f34"
integrity sha512-fcQztozJ8jToQWXxVuEyXWW+dSo8AiXWKwiSSrKWsRB/Qt+Ewwza+JWoLKiTuQLaEPhdNAJ7+Dosc9DOIqNy7Q==

bootstrap@~3.4.0:
version "3.4.1"
resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-3.4.1.tgz#c3a347d419e289ad11f4033e3c4132b87c081d72"
Expand Down Expand Up @@ -543,9 +548,9 @@ [email protected]:
integrity sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=

extsprintf@^1.2.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f"
integrity sha1-4mifjzVvrWLMplo6kcXfX5VRaS8=
version "1.4.1"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.1.tgz#8d172c064867f235c0c84a596806d279bf4bcc07"
integrity sha512-Wrk35e8ydCKDj/ArClo1VrPVmN8zph5V4AtHwIuHhvMXsKf73UT3BOD+azBIW+3wOJ4FhEH7zyaJCFvChjYvMA==

fast-deep-equal@^3.1.1:
version "3.1.3"
Expand Down Expand Up @@ -943,24 +948,24 @@ json-schema-traverse@^0.4.1:
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660"
integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==

json-schema@0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13"
integrity sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=
json-schema@0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.4.0.tgz#f7de4cf6efab838ebaeb3236474cbba5a1930ab5"
integrity sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==

json-stringify-safe@~5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=

jsprim@^1.2.2:
version "1.4.1"
resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2"
integrity sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=
version "1.4.2"
resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.2.tgz#712c65533a15c878ba59e9ed5f0e26d5b77c5feb"
integrity sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==
dependencies:
assert-plus "1.0.0"
extsprintf "1.3.0"
json-schema "0.2.3"
json-schema "0.4.0"
verror "1.10.0"

junction@theleagueof/junction#*:
Expand Down Expand Up @@ -1033,22 +1038,22 @@ [email protected]:
resolved "https://registry.yarnpkg.com/methods/-/methods-1.0.1.tgz#75bc91943dffd7da037cf3eeb0ed73a0037cd14b"
integrity sha1-dbyRlD3/19oDfPPusO1zoAN80Us=

mime-db@1.49.0:
version "1.49.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.49.0.tgz#f3dfde60c99e9cf3bc9701d687778f537001cbed"
integrity sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA==
mime-db@1.51.0:
version "1.51.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.51.0.tgz#d9ff62451859b18342d960850dc3cfb77e63fb0c"
integrity sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g==

[email protected]:
version "1.0.0"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-1.0.0.tgz#6a7b4a6af2e7d92f97afe03f047c7801e8f001d2"
integrity sha1-antKavLn2S+Xr+A/BHx4AejwAdI=

mime-types@^2.1.12, mime-types@~2.1.19:
version "2.1.32"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.32.tgz#1d00e89e7de7fe02008db61001d9e02852670fd5"
integrity sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==
version "2.1.34"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.34.tgz#5a712f9ec1503511a945803640fafe09d3793c24"
integrity sha512-6cP692WwGIs9XXdOO4++N+7qjqv0rqxxVvJ3VHPh/Sc9mVZcQP+ZGhkKiTvWMQRr2tbHkJP/Yn7Y0npb3ZBs4A==
dependencies:
mime-db "1.49.0"
mime-db "1.51.0"

[email protected], mime@~1.2.11:
version "1.2.11"
Expand Down Expand Up @@ -1173,9 +1178,9 @@ object-assign@^4.1.0:
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=

object-inspect@^1.9.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.11.0.tgz#9dceb146cedd4148a0d9e51ab88d34cf509922b1"
integrity sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg==
version "1.12.0"
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.12.0.tgz#6e2c120e868fd1fd18cb4f18c31741d0d6e776f0"
integrity sha512-Ho2z80bVIvJloH+YzRmpZVQe87+qASmBUKZDWgx9cu+KDrX2ZDH/3tMy+gXbZETVGs2M8YdxObOh7XAtim9Y0g==

[email protected]:
version "0.0.0"
Expand Down Expand Up @@ -1266,9 +1271,9 @@ [email protected]:
integrity sha1-bgFQmP9RlouKPIGQAdXyyJvEsQc=

qs@^6.4.0:
version "6.10.1"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.10.1.tgz#4931482fa8d647a5aab799c5271d2133b981fb6a"
integrity sha512-M528Hph6wsSVOBiYUnGf+K/7w0hNshs/duGsNXPUCLH5XAqjEtiPGwNONLV0tBH8NoGb0mvD5JubnUTrujKDTg==
version "6.10.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.10.2.tgz#c1431bea37fc5b24c5bdbafa20f16bdf2a4b9ffe"
integrity sha512-mSIdjzqznWgfd4pMii7sHtaYF8rx8861hBO80SraY5GT0XQibWZWJSid0avzHGkDIZLImux2S5mXO0Hfct2QCw==
dependencies:
side-channel "^1.0.4"

Expand Down