Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit 16b3b9e

Browse files
committed
inserted rubocop; fixed tests to neo4j
1 parent 0862416 commit 16b3b9e

File tree

20 files changed

+284
-131
lines changed

20 files changed

+284
-131
lines changed

.rubocop.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
AllCops:
2+
TargetRubyVersion: 2.7.1
3+
Exclude:
4+
- "Gemfile"
5+
- "Gemfile.lock"
6+
- "db/schema.rb"
7+
8+
Layout/ParameterAlignment:
9+
EnforcedStyle: with_fixed_indentation
10+
11+
Layout/DotPosition:
12+
EnforcedStyle: trailing
13+
14+
Layout/FirstHashElementIndentation:
15+
EnforcedStyle: consistent
16+
17+
Layout/MultilineMethodCallIndentation:
18+
EnforcedStyle: indented
19+
20+
Layout/EmptyLinesAroundAttributeAccessor:
21+
Enabled: true
22+
23+
Layout/SpaceAroundMethodCallOperator:
24+
Enabled: true
25+
26+
Lint/DeprecatedOpenSSLConstant:
27+
Enabled: true
28+
29+
Lint/MixedRegexpCaptureTypes:
30+
Enabled: true
31+
32+
Lint/RaiseException:
33+
Enabled: true
34+
35+
Lint/StructNewOverride:
36+
Enabled: true
37+
38+
Style/Documentation:
39+
Enabled: false
40+
41+
Style/FrozenStringLiteralComment:
42+
Enabled: false
43+
44+
Style/AsciiComments:
45+
Enabled: false
46+
47+
Style/TrailingCommaInHashLiteral:
48+
EnforcedStyleForMultiline: comma
49+
50+
Style/TrailingCommaInArrayLiteral:
51+
EnforcedStyleForMultiline: comma
52+
53+
Style/ExponentialNotation:
54+
Enabled: true
55+
56+
Style/HashEachMethods:
57+
Enabled: true
58+
59+
Style/HashTransformKeys:
60+
Enabled: true
61+
62+
Style/HashTransformValues:
63+
Enabled: true
64+
65+
Style/RedundantRegexpCharacterClass:
66+
Enabled: true
67+
68+
Style/RedundantRegexpEscape:
69+
Enabled: true
70+
71+
Style/SlicingWithRange:
72+
Enabled: true

README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
1-
# README
1+
# Angora
22

3-
This README would normally document whatever steps are necessary to get the
4-
application up and running.
3+
## Dependencies
54

6-
Things you may want to cover:
5+
* Docker https://docs.docker.com
6+
* Docker Compose https://docs.docker.com/compose/
77

8-
* Ruby version
8+
## Running
99

10-
* System dependencies
10+
Run the below code:
1111

12-
* Configuration
13-
14-
* Database creation
12+
```
13+
docker-compose run web
14+
```
1515

16-
* Database initialization
16+
## Setup
1717

18-
* How to run the test suite
18+
You need execute migrations to neo4j and populate database with default test data to see the system works.
1919

20-
* Services (job queues, cache servers, search engines, etc.)
20+
```
21+
docker-compose run web rails neo4j:migrate RAILS_ENV=development
22+
docker-compose run web rake db:seed
23+
```
2124

22-
* Deployment instructions
25+
## Testing
2326

24-
* ...
27+
Run the below code:
2528

26-
## Debugging with `byebug`
29+
```
30+
docker-compose run web rails test
31+
```
2732

28-
## Docker compos config
33+
## Debugging with `byebug` inside the Docker
2934

3035
```yaml
3136
app:
@@ -37,7 +42,7 @@ This also makes it possible to after the containers are up do `docker attach ang
3742

3843
https://github.com/docker/compose/issues/423#issuecomment-141995398
3944

40-
## Neo4j
45+
## Neo4j tips
4146

4247
### Removing data
4348

app/controllers/application_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ class ApplicationController < ActionController::Base
33

44
def set_session_user_id
55
if session[:session_user_id].present?
6-
@current_user = User.find(session[:session_user_id]) rescue nil
6+
@current_user = begin
7+
User.find(session[:session_user_id])
8+
rescue StandardError
9+
nil
10+
end
711
end
812

913
@current_user = User.first if @current_user.nil?

app/controllers/users_controller.rb

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class UsersController < ApplicationController
22
ACTIVE_MODEL_CLASS = User # UserNeo4j
33

4-
before_action :set_user, only: [:show, :friends, :edit, :update, :destroy, :invite]
4+
before_action :set_user, only: %i[show friends edit update destroy invite]
55

66
# GET /users
77
# GET /users.json
@@ -12,13 +12,22 @@ def index
1212
# GET /users/1
1313
# GET /users/1.json
1414
def show
15-
@user_neo4j = UserNeo4j.find(@user.neo4j_uuid)
16-
@friends_path = {}
15+
user_neo4j = UserNeo4j.find(@user.neo4j_uuid)
1716

1817
if params[:q].present?
19-
@friends, @friends_path = @user_neo4j.friendsBySearch(params[:q])
20-
elsif @user_neo4j.present?
21-
@friends = @user_neo4j.friends
18+
friends, friends_path = user_neo4j.friends_by_search(params[:q])
19+
elsif user_neo4j.present?
20+
friends = user_neo4j.friends
21+
end
22+
23+
# FIXME: Change this When use ACTIVE_MODEL_CLASS as UserNeo4j
24+
@friends = User.where(:neo4j_uuid.in => friends.pluck(:uuid))
25+
@friends_path = friends_path&.transform_values do |item|
26+
uuids = item.map { |node| node.props[:uuid] }
27+
28+
# it is necessary to order after query in database to preser correct path
29+
User.where(:neo4j_uuid.in => uuids).
30+
to_a.sort_by { |value| uuids.index(value.neo4j_uuid) }
2231
end
2332
end
2433

@@ -39,8 +48,7 @@ def new
3948
end
4049

4150
# GET /users/1/edit
42-
def edit
43-
end
51+
def edit; end
4452

4553
# POST /users
4654
# POST /users.json
@@ -76,19 +84,12 @@ def update
7684
# GET /users/1/invite.json
7785
def invite
7886
notice = 'User was successfully invited.'
79-
friend_a = UserNeo4j.find(@current_user.neo4j_uuid)
80-
friend_b = UserNeo4j.find(@user.neo4j_uuid)
81-
82-
if friend_a.friends(rel_length: 1).where({ uuid: @user.neo4j_uuid }).present?
83-
notice = 'User was successfully uninvited.'
84-
friend_a.friends.delete(friend_b)
85-
friend_b.friends.delete(friend_a)
86-
else
87-
friend_a.friends << friend_b
88-
friend_b.friends << friend_a
89-
end
87+
88+
neo4j = UserNeo4j.find(@current_user.neo4j_uuid)
89+
neo4j.invite(@user.neo4j_uuid)
9090

9191
respond_to do |format|
92+
format.js { render json: { status: :ok, message: notice } }
9293
format.html { redirect_to user_path(@user), notice: notice }
9394
format.json { render json: { status: :ok, message: notice } }
9495
end

app/helpers/users_helper.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
module UsersHelper
22
def invite_link_to(user)
33
neo4j = UserNeo4j.find(@current_user.neo4j_uuid)
4-
invited = neo4j.friends.find(user.neo4j_uuid).present? rescue nil
4+
invited = begin
5+
neo4j.friends.find(user.neo4j_uuid).present?
6+
rescue StandardError
7+
nil
8+
end
59

610
link_to invite_user_path(user), class: "card-footer-item btn-invite #{'is-active' if invited}" do
711
content_tag(:div, nil, class: 'heart') + ' Invite'
812
end
9-
rescue
13+
rescue StandardError
1014
nil
1115
end
1216

app/models/concerns/user_sync.rb

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ module UserSync
99
def save_neoj4
1010
return unless (attributes.keys - ['updated_at']).any?
1111

12-
params = attributes.slice(*%w[
13-
first_name
14-
last_name
15-
slug
16-
website
17-
titles
18-
subtitles
19-
introduction
20-
]).merge({ 'skip_get_website_titles' => true })
12+
params = attributes.slice(
13+
'first_name',
14+
'last_name',
15+
'slug',
16+
'website',
17+
'titles',
18+
'subtitles',
19+
'introduction'
20+
).merge({ 'skip_load_website_titles' => true })
2121

2222
if neo4j_uuid.present?
2323
user = UserNeo4j.find(neo4j_uuid)
2424
user.update(params)
25-
elsif
25+
else
2626
user = UserNeo4j.create(params)
2727

2828
# update without callbacks
@@ -33,7 +33,11 @@ def save_neoj4
3333
def destroy_neoj4
3434
return unless neo4j_uuid.present?
3535

36-
UserNeo4j.find(neo4j_uuid).destroy rescue nil
36+
begin
37+
UserNeo4j.find(neo4j_uuid).destroy
38+
rescue StandardError
39+
nil
40+
end
3741

3842
set({ neo4j_uuid: nil })
3943
end

app/models/user.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ class User
1515
field :introduction, type: String
1616
field :neo4j_uuid, type: String
1717

18-
attr_accessor :skip_get_website_titles
18+
attr_accessor :skip_load_website_titles
1919

20-
slug :first_name, reserve: ['admin', 'root'] + RouteRecognizer.initial_path_segments
20+
slug :first_name, reserve: %w[admin root] + RouteRecognizer.initial_path_segments
2121

2222
validates :first_name, presence: true
23-
validates :website, uniqueness: true, presence: true, website: true, unless: :skip_get_website_titles
23+
validates :website, uniqueness: true, presence: true, website: true, unless: :skip_load_website_titles
2424

25-
after_save :get_website_titles, unless: :skip_get_website_titles
25+
after_save :load_website_titles, unless: :skip_load_website_titles
2626
after_create :clear_database
2727

2828
def full_name
@@ -42,7 +42,7 @@ def reload_titles!
4242

4343
protected
4444

45-
def get_website_titles
45+
def load_website_titles
4646
return unless changed_attributes.keys.include?('website')
4747

4848
reload_titles!
@@ -61,15 +61,15 @@ def clear_database
6161

6262
# Used as default user list on start project
6363
DEFAULT_USERS = [
64-
{ first_name: 'Vinnie', last_name: 'Lintott', website: 'http://indiatimes.com', titles: [''], skip_get_website_titles: true },
65-
{ first_name: 'Otha', last_name: 'Kunes', website: 'https://edublogs.org', titles: ['.NET'], skip_get_website_titles: true },
66-
{ first_name: 'Dayle', last_name: 'Caswill', website: 'http://sohu.com', titles: ['C', 'C++'], skip_get_website_titles: true },
67-
{ first_name: 'Erastus', last_name: 'Quilligan', website: 'http://skyrock.com', titles: ['Javascript', 'ASP'], skip_get_website_titles: true },
68-
{ first_name: 'Jamal', last_name: 'Cullington', website: 'https://webmd.com', titles: ['Pascal'], skip_get_website_titles: true },
69-
{ first_name: 'Joice', last_name: 'Brooke', website: 'http://marketwatch.com', titles: ['Python'], skip_get_website_titles: true },
70-
{ first_name: 'Gwenni', last_name: 'Dines', website: 'http://typepad.com', titles: ['Go'], skip_get_website_titles: true },
71-
{ first_name: 'Glyn', last_name: 'Clouter', website: 'https://google.ru', titles: ['PHP', 'Ruby'], skip_get_website_titles: true },
72-
{ first_name: 'Lucienne', last_name: 'Ready', website: 'http://myspace.com', titles: ['Ruby'], skip_get_website_titles: true },
73-
{ first_name: 'Katuscha', last_name: 'Tinman', website: 'http://umn.edu', titles: ['Java'], skip_get_website_titles: true },
74-
]
64+
{ first_name: 'Vinnie', last_name: 'Lintott', website: 'http://indiatimes.com', titles: [''], skip_load_website_titles: true },
65+
{ first_name: 'Otha', last_name: 'Kunes', website: 'https://edublogs.org', titles: ['.NET'], skip_load_website_titles: true },
66+
{ first_name: 'Dayle', last_name: 'Caswill', website: 'http://sohu.com', titles: ['C', 'C++'], skip_load_website_titles: true },
67+
{ first_name: 'Erastus', last_name: 'Quilligan', website: 'http://skyrock.com', titles: %w[Javascript ASP], skip_load_website_titles: true },
68+
{ first_name: 'Jamal', last_name: 'Cullington', website: 'https://webmd.com', titles: ['Pascal'], skip_load_website_titles: true },
69+
{ first_name: 'Joice', last_name: 'Brooke', website: 'http://marketwatch.com', titles: ['Python'], skip_load_website_titles: true },
70+
{ first_name: 'Gwenni', last_name: 'Dines', website: 'http://typepad.com', titles: ['Go'], skip_load_website_titles: true },
71+
{ first_name: 'Glyn', last_name: 'Clouter', website: 'https://google.ru', titles: %w[PHP Ruby], skip_load_website_titles: true },
72+
{ first_name: 'Lucienne', last_name: 'Ready', website: 'http://myspace.com', titles: ['Ruby'], skip_load_website_titles: true },
73+
{ first_name: 'Katuscha', last_name: 'Tinman', website: 'http://umn.edu', titles: ['Java'], skip_load_website_titles: true },
74+
].freeze
7575
end

0 commit comments

Comments
 (0)