Skip to content

Commit 283a48c

Browse files
committed
Ruby: tests for OrmWriteAccess
1 parent 8c6c680 commit 283a48c

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
| app/controllers/users/users_controller.rb:5:7:5:44 | call to create! | name | app/controllers/users/users_controller.rb:5:26:5:29 | "U1" |
2+
| app/controllers/users/users_controller.rb:5:7:5:44 | call to create! | uid | app/controllers/users/users_controller.rb:5:37:5:43 | call to get_uid |
3+
| app/controllers/users/users_controller.rb:6:7:6:29 | call to create | name | app/controllers/users/users_controller.rb:6:25:6:28 | "U2" |
4+
| app/controllers/users/users_controller.rb:7:7:7:31 | call to insert | name | app/controllers/users/users_controller.rb:7:26:7:29 | "U3" |
5+
| app/controllers/users/users_controller.rb:10:7:10:32 | call to update | name | app/controllers/users/users_controller.rb:10:28:10:31 | "U4" |
6+
| app/controllers/users/users_controller.rb:11:7:11:73 | call to update! | name | app/controllers/users/users_controller.rb:11:39:11:42 | "U5" |
7+
| app/controllers/users/users_controller.rb:11:7:11:73 | call to update! | name | app/controllers/users/users_controller.rb:11:53:11:56 | "U6" |
8+
| app/controllers/users/users_controller.rb:11:7:11:73 | call to update! | name | app/controllers/users/users_controller.rb:11:67:11:70 | "U7" |
9+
| app/controllers/users/users_controller.rb:14:7:14:66 | call to insert_all | name | app/controllers/users/users_controller.rb:14:31:14:34 | "U8" |
10+
| app/controllers/users/users_controller.rb:14:7:14:66 | call to insert_all | name | app/controllers/users/users_controller.rb:14:45:14:48 | "U9" |
11+
| app/controllers/users/users_controller.rb:14:7:14:66 | call to insert_all | name | app/controllers/users/users_controller.rb:14:59:14:63 | "U10" |
12+
| app/controllers/users/users_controller.rb:19:7:19:30 | call to update | name | app/controllers/users/users_controller.rb:19:25:19:29 | "U11" |
13+
| app/controllers/users/users_controller.rb:20:7:20:57 | call to update_attributes | name | app/controllers/users/users_controller.rb:20:37:20:41 | "U12" |
14+
| app/controllers/users/users_controller.rb:20:7:20:57 | call to update_attributes | uid | app/controllers/users/users_controller.rb:20:49:20:55 | call to get_uid |
15+
| app/controllers/users/users_controller.rb:23:7:23:42 | call to update_attribute | name | app/controllers/users/users_controller.rb:23:37:23:41 | "U13" |
16+
| app/controllers/users/users_controller.rb:26:7:26:15 | call to name= | name | app/controllers/users/users_controller.rb:26:19:26:23 | "U14" |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import codeql.ruby.DataFlow
2+
import codeql.ruby.Concepts
3+
4+
query predicate ormFieldWrites(OrmWriteAccess acc, string fieldName, DataFlow::Node value) {
5+
fieldName = acc.getFieldNameAssignedTo(value)
6+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Users
2+
class UsersController < ApplicationController
3+
def create_or_modify
4+
# CreateLikeCall
5+
User.create!(name: "U1", uid: get_uid)
6+
User.create(name: "U2")
7+
User.insert({name: "U3"})
8+
9+
# UpdateLikeClassMethodCall
10+
User.update(4, name: "U4")
11+
User.update!([5, 6, 7], [{name: "U5"}, {name: "U6"}, {name: "U7"}])
12+
13+
# InsertAllLikeCall
14+
User.insert_all([{name: "U8"}, {name: "U9"}, {name: "U10"}])
15+
16+
user = User.find(5)
17+
18+
# UpdateLikeInstanceMethodCall
19+
user.update(name: "U11")
20+
user.update_attributes({name: "U12", uid: get_uid})
21+
22+
# UpdateAttributeCall
23+
user.update_attribute("name", "U13")
24+
25+
# AssignAttributeCall
26+
user.name = "U14"
27+
user.save
28+
end
29+
30+
def get_uid
31+
User.last.id + 1
32+
end
33+
end
34+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ApplicationRecord < ActiveRecord::Base
2+
self.abstract_class = true
3+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class User < ApplicationRecord
2+
end

0 commit comments

Comments
 (0)