Przeglądaj źródła

Merge branch 'fix_membership' of cli/Chronobriq-API into master

nas 2 lat temu
rodzic
commit
b46912ab42

+ 4
- 0
.dockerignore Wyświetl plik

@@ -0,0 +1,4 @@
1
+erd.pdf
2
+.git
3
+.gitignore
4
+.gitattributes

+ 65
- 0
Dockerfile Wyświetl plik

@@ -0,0 +1,65 @@
1
+# 
2
+# This is an unofficial Alpine image embedding rbenv
3
+# Inspired by https://github.com/didlich/docker-alpine-rbenv/blob/master/Dockerfile
4
+# 
5
+
6
+FROM alpine:3.15
7
+
8
+RUN apk add --update \
9
+    bash \
10
+    git \
11
+    wget \
12
+    curl \
13
+    vim \
14
+    build-base \
15
+    readline-dev \
16
+    openssl-dev \
17
+    zlib-dev \
18
+&& rm -rf /var/cache/apk/*
19
+
20
+# rbenv
21
+ENV PATH /usr/local/rbenv/shims:/usr/local/rbenv/bin:$PATH
22
+ENV RBENV_ROOT /usr/local/rbenv
23
+ENV RUBY_VERSION 3.0.2
24
+ENV CONFIGURE_OPTS --disable-install-doc
25
+
26
+RUN apk add --update \
27
+    linux-headers \
28
+    imagemagick-dev \    
29
+    libffi-dev \    
30
+    libffi-dev \
31
+	libpq-dev \
32
+	&& rm -rf /var/cache/apk/*
33
+
34
+RUN git clone --depth 1 git://github.com/sstephenson/rbenv.git ${RBENV_ROOT} \
35
+&&  git clone --depth 1 https://github.com/sstephenson/ruby-build.git ${RBENV_ROOT}/plugins/ruby-build \
36
+&&  git clone --depth 1 git://github.com/jf/rbenv-gemset.git ${RBENV_ROOT}/plugins/rbenv-gemset \
37
+&& ${RBENV_ROOT}/plugins/ruby-build/install.sh
38
+
39
+RUN echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh 
40
+
41
+RUN rbenv install $RUBY_VERSION \
42
+&&  rbenv global $RUBY_VERSION
43
+
44
+RUN gem install bundler
45
+
46
+WORKDIR /app
47
+
48
+# Getting required gems
49
+COPY Gemfile ./
50
+RUN bundle install
51
+
52
+COPY [^Gemfile]* ./
53
+
54
+# RUN RAILS_ENV=production / db:create
55
+# RUN / db:migrate
56
+
57
+# Deleting useless packages
58
+# RUN apk del git wget curl build-base \
59
+#     rm -rf /var/cache/apk/*
60
+
61
+EXPOSE 9000
62
+
63
+CMD [ "top" ]
64
+
65
+# CMD [ "rails", "server", "-p 9000", "-b 127.0.0.1", "-e production" ]

+ 36
- 40
README.md Wyświetl plik

@@ -16,7 +16,7 @@ PostgreSQL 11 minimum et la gem associée (`pg`).
16 16
 3. `rails server` pour lancer un serveur local de développement sur le port 3000
17 17
 
18 18
 ### 2. Endpoints
19
-La commande `rails routes` fournie l'ensemble des endpoints et requêtes HTTP disponibles. L'ensemble des requêtes se font sur la base : localhost:3000/api/v1.
19
+La commande `rails routes` fournie l'ensemble des endpoints et requêtes HTTP disponibles. L'ensemble des requêtes se font sur la base : domaine.tld/api/v1.
20 20
 
21 21
 ## Tests
22 22
 
@@ -70,42 +70,38 @@ Patch et delete permettent de modifier ou supprimer une donnée qui a été cré
70 70
 
71 71
 ### Routes
72 72
 
73
-|               Prefix | Verb   | URI Pattern                                                | Controller#Action                           |
74
-| -------------------- | ------ | ---------------------------------------------------------- | ------------------------------------------- |
75
-|          api_v1_users| GET    | /api/v1/users(.:format)                                    | api/v1/users#index {:format=>:json}         |
76
-|                      | POST   | /api/v1/users(.:format)                                    | api/v1/users#create {:format=>:json}        |
77
-|           api_v1_user| GET    | /api/v1/users/:id(.:format)                                | api/v1/users#show {:format=>:json}          |
78
-|                      | PATCH  | /api/v1/users/:id(.:format)                                | api/v1/users#update {:format=>:json}        |
79
-|                      | PUT    | /api/v1/users/:id(.:format)                                | api/v1/users#update {:format=>:json}        |
80
-|                      | DELETE | /api/v1/users/:id(.:format)                                | api/v1/users#destroy {:format=>:json}       |
81
-|         api_v1_tokens| POST   | /api/v1/tokens(.:format)                                   | api/v1/tokens#create {:format=>:json}       |
82
-|          api_v1_teams| GET    | /api/v1/teams(.:format)                                    | api/v1/teams#index {:format=>:json}         |
83
-|                      | POST   | /api/v1/teams(.:format)                                    | api/v1/teams#create {:format=>:json}        |
84
-|           api_v1_team| GET    | /api/v1/teams/:id(.:format)                                | api/v1/teams#show {:format=>:json}          |
85
-|                      | PATCH  | /api/v1/teams/:id(.:format)                                | api/v1/teams#update {:format=>:json}        |
86
-|                      | PUT    | /api/v1/teams/:id(.:format)                                | api/v1/teams#update {:format=>:json}        |
87
-|                      | DELETE | /api/v1/teams/:id(.:format)                                | api/v1/teams#destroy {:format=>:json}       |
88
-|    api_v1_memberships| GET    | /api/v1/memberships(.:format)                              | api/v1/memberships#index {:format=>:json}   |
89
-|                      | POST   | /api/v1/memberships(.:format)                              | api/v1/memberships#create {:format=>:json}  |
90
-|     api_v1_membership| GET    | /api/v1/memberships/:id(.:format)                          | api/v1/memberships#show {:format=>:json}    |
91
-|                      | PATCH  | /api/v1/memberships/:id(.:format)                          | api/v1/memberships#update {:format=>:json}  |
92
-|                      | PUT    | /api/v1/memberships/:id(.:format)                          | api/v1/memberships#update {:format=>:json}  |
93
-|                      | DELETE | /api/v1/memberships/:id(.:format)                          | api/v1/memberships#destroy {:format=>:json} |
94
-| api_v1_activity_tasks| GET    | /api/v1/activities/:activity_id/tasks(.:format)            | api/v1/tasks#index {:format=>:json}         |
95
-|                      | POST   | /api/v1/activities/:activity_id/tasks(.:format)            | api/v1/tasks#create {:format=>:json}       |
96
-|  api_v1_activity_task| GET    | /api/v1/activities/:activity_id/tasks/:id(.:format)        | api/v1/tasks#show {:format=>:json}         |
97
-|                      | PATCH  | /api/v1/activities/:activity_id/tasks/:id(.:format)        | api/v1/tasks#update {:format=>:json}       |
98
-|                      | PUT    | /api/v1/activities/:activity_id/tasks/:id(.:format)        | api/v1/tasks#update {:format=>:json}       |
99
-|                      | DELETE | /api/v1/activities/:activity_id/tasks/:id(.:format)        | api/v1/tasks#destroy {:format=>:json}      |
100
-|     api_v1_activities| GET    | /api/v1/activities(.:format)                               | api/v1/activities#index {:format=>:json}   |
101
-|                      | POST   | /api/v1/activities(.:format)                               | api/v1/activities#create {:format=>:json}  |
102
-|       api_v1_activity| GET    | /api/v1/activities/:id(.:format)                           | api/v1/activities#show {:format=>:json}    |
103
-|                      | PATCH  | /api/v1/activities/:id(.:format)                           | api/v1/activities#update {:format=>:json}  |
104
-|                      | PUT    | /api/v1/activities/:id(.:format)                           | api/v1/activities#update {:format=>:json}  |
105
-|                      | DELETE | /api/v1/activities/:id(.:format)                           | api/v1/activities#destroy {:format=>:json} |
106
-|          api_v1_tasks| GET    | /api/v1/tasks(.:format)                                    | api/v1/tasks#index {:format=>:json}        |
107
-|                      | POST   | /api/v1/tasks(.:format)                                    | api/v1/tasks#create {:format=>:json}       |
108
-|           api_v1_task| GET    | /api/v1/tasks/:id(.:format)                                | api/v1/tasks#show {:format=>:json}         |
109
-|                      | PATCH  | /api/v1/tasks/:id(.:format)                                | api/v1/tasks#update {:format=>:json}       |
110
-|                      | PUT    | /api/v1/tasks/:id(.:format)                                | api/v1/tasks#update {:format=>:json}       |
111
-|                      | DELETE | /api/v1/tasks/:id(.:format)                                | api/v1/tasks#destroy {:format=>:json}      |
73
+|                Prefix | Verb   | URI Pattern                                                | Controller#Action                           |
74
+| --------------------- | ------ | ---------------------------------------------------------- | ------------------------------------------- |
75
+|           api_v1_users| GET    | /api/v1/users(.:format)                                    | api/v1/users#index {:format=>:json}         |
76
+|                       | POST   | /api/v1/users(.:format)                                    | api/v1/users#create {:format=>:json}        |
77
+|            api_v1_user| GET    | /api/v1/users/:id(.:format)                                | api/v1/users#show {:format=>:json}          |
78
+|                       | PATCH  | /api/v1/users/:id(.:format)                                | api/v1/users#update {:format=>:json}        |
79
+|                       | PUT    | /api/v1/users/:id(.:format)                                | api/v1/users#update {:format=>:json}        |
80
+|                       | DELETE | /api/v1/users/:id(.:format)                                | api/v1/users#destroy {:format=>:json}       |
81
+|          api_v1_tokens| POST   | /api/v1/tokens(.:format)                                   | api/v1/tokens#create {:format=>:json}       |
82
+|api_v1_team_memberships| GET    | /api/v1/teams/:team_id/memberships(.:format)               | api/v1/memberships#index {:format=>:json}   |
83
+|                       | POST   | /api/v1/teams/:team_id/memberships(.:format)               | api/v1/memberships#create {:format=>:json}  |
84
+| api_v1_team_membership| GET    | /api/v1/teams/:team_id/memberships/:id(.:format)           | api/v1/memberships#show {:format=>:json}    |
85
+|                       |PATCH   | /api/v1/teams/:team_id/memberships/:id(.:format)           | api/v1/memberships#update {:format=>:json}  |
86
+|                       | PUT    | /api/v1/teams/:team_id/memberships/:id(.:format)           | api/v1/memberships#update {:format=>:json}  |
87
+|                       | DELETE | /api/v1/teams/:team_id/memberships/:id(.:format)           | api/v1/memberships#destroy {:format=>:json} |
88
+|          api_v1_teams| GET    | /api/v1/teams(.:format)                                     | api/v1/teams#index {:format=>:json}         |
89
+|                      | POST   | /api/v1/teams(.:format)                                     | api/v1/teams#create {:format=>:json}        |
90
+|           api_v1_team| GET    | /api/v1/teams/:id(.:format)                                 | api/v1/teams#show {:format=>:json}          |
91
+|                      | PATCH  | /api/v1/teams/:id(.:format)                                 | api/v1/teams#update {:format=>:json}        |
92
+|                      | PUT    | /api/v1/teams/:id(.:format)                                 | api/v1/teams#update {:format=>:json}        |
93
+|                      | DELETE | /api/v1/teams/:id(.:format)                                 | api/v1/teams#destroy {:format=>:json}       |
94
+|   api_v1_memberships | GET    | /api/v1/memberships(.:format)                               |api/v1/memberships#index {:format=>:json}    |
95
+| api_v1_activity_tasks| GET    | /api/v1/activities/:activity_id/tasks(.:format)             | api/v1/tasks#index {:format=>:json}         |
96
+|                      | POST   | /api/v1/activities/:activity_id/tasks(.:format)             | api/v1/tasks#create {:format=>:json}        |
97
+|  api_v1_activity_task| GET    | /api/v1/activities/:activity_id/tasks/:id(.:format)         | api/v1/tasks#show {:format=>:json}          |
98
+|                      | PATCH  | /api/v1/activities/:activity_id/tasks/:id(.:format)         | api/v1/tasks#update {:format=>:json}        |
99
+|                      | PUT    | /api/v1/activities/:activity_id/tasks/:id(.:format)         | api/v1/tasks#update {:format=>:json}        |
100
+|                      | DELETE | /api/v1/activities/:activity_id/tasks/:id(.:format)         | api/v1/tasks#destroy {:format=>:json}       |
101
+|     api_v1_activities| GET    | /api/v1/activities(.:format)                                | api/v1/activities#index {:format=>:json}    |
102
+|                      | POST   | /api/v1/activities(.:format)                                | api/v1/activities#create {:format=>:json}   |
103
+|       api_v1_activity| GET    | /api/v1/activities/:id(.:format)                            | api/v1/activities#show {:format=>:json}     |
104
+|                      | PATCH  | /api/v1/activities/:id(.:format)                            | api/v1/activities#update {:format=>:json}   |
105
+|                      | PUT    | /api/v1/activities/:id(.:format)                            | api/v1/activities#update {:format=>:json}   |
106
+|                      | DELETE | /api/v1/activities/:id(.:format)                            | api/v1/activities#destroy {:format=>:json}  |
107
+|          api_v1_tasks| GET    | /api/v1/tasks(.:format)                                     | api/v1/tasks#index {:format=>:json}         |

+ 12
- 10
app/controllers/api/v1/memberships_controller.rb Wyświetl plik

@@ -3,19 +3,21 @@ class Api::V1::MembershipsController < ApplicationController
3 3
   before_action :check_login
4 4
 
5 5
   def index
6
-    render json: MembershipSerializer.new(Membership.all).serializable_hash.to_json
6
+    if !params[:team_id]
7
+      render json: MembershipSerializer.new(Membership.all).serializable_hash.to_json
8
+    else
9
+      render json: MembershipSerializer.new(Team.find(params[:team_id]).memberships).serializable_hash.to_json
10
+    end
7 11
   end
8
-
12
+  
9 13
   def show
10 14
     render json: MembershipSerializer.new(@membership).serializable_hash.to_json
11 15
   end
12 16
 
13
-  def create
14
-    member_id = User.where(username: params[:membership][:username])[0].id
15
-    team_id = Team.where(name: params[:membership][:team_name])[0].id
16
-
17
-    membership = Membership.new(team_id: team_id, member_id: member_id, can_edit: false)
18
-    
17
+  def create  
18
+    membership = current_user.memberships.build(membership_params)
19
+    membership.team_id = params[:team_id]
20
+  
19 21
     if membership.save
20 22
       render json: MembershipSerializer.new(membership).serializable_hash.to_json, status: :created
21 23
     else
@@ -25,7 +27,7 @@ class Api::V1::MembershipsController < ApplicationController
25 27
 
26 28
   def update
27 29
     if params[:membership][:can_edit] 
28
-      if @membership.update(memberships_params)
30
+      if @membership.update(membership_params)
29 31
         render json: MembershipSerializer.new(@membership).serializable_hash.to_json, status: :ok
30 32
       else
31 33
         render json: @membership.errors, status: :unprocessable_entity
@@ -42,7 +44,7 @@ class Api::V1::MembershipsController < ApplicationController
42 44
 
43 45
   private
44 46
 
45
-  def memberships_params
47
+  def membership_params
46 48
     params.require(:membership).permit(:can_edit)
47 49
   end
48 50
   

+ 1
- 1
app/models/activity.rb Wyświetl plik

@@ -5,7 +5,7 @@ class Activity < ApplicationRecord
5 5
   has_one :user, :through => :joined_user_activity
6 6
 
7 7
   has_many :tasks
8
-
8
+  
9 9
   validates :name, presence: true
10 10
   validates :author, presence: true
11 11
 end

+ 0
- 3
app/models/membership.rb Wyświetl plik

@@ -1,7 +1,4 @@
1 1
 class Membership < ApplicationRecord
2
-  # attr_readonly :member
3
-  # attr_readonly :team
4
-
5 2
   validates :member, presence: :true
6 3
   validates :team, presence: :true
7 4
   validates_uniqueness_of :member, scope: :team, message: "user already part of this team"

+ 3
- 3
app/models/task.rb Wyświetl plik

@@ -1,9 +1,9 @@
1 1
 class Task < ApplicationRecord
2
+  belongs_to :activity
3
+  belongs_to :owner, class_name: "User"
4
+
2 5
   validates :name, presence: true
3 6
   validates :owner, presence: true
4 7
   validates :activity, presence: true
5 8
   validates :start_time, presence: true
6
-
7
-  belongs_to :activity
8
-  belongs_to :owner, class_name: "User"
9 9
 end

+ 13
- 23
config/database.yml Wyświetl plik

@@ -1,31 +1,21 @@
1
-# SQLite. Versions 3.8.0 and up are supported.
2
-#   gem install sqlite3
3
-#
4
-#   Ensure the SQLite 3 gem is defined in your Gemfile
5
-#   gem 'sqlite3'
6
-#
7 1
 default: &default
8
-  # adapter: sqlite3
9
-  adapter: postgresql
10
-  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
11
-  timeout: 5000
12
-  username: <%= ENV['PG_USER'] %>
13
-  password: <%= ENV['PG_USER_PWD'] %>
14
-
15
-development:
16
-  <<: *default
17
-  # database: db/development.sqlite3
18
-  database: chronobriq_development
2
+    adapter: postgresql
3
+    pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
4
+    timeout: 5000
5
+    username: <%= ENV['PG_USER'] %>
6
+    password: <%= ENV['PG_USER_PWD'] %>
19 7
 
20 8
 # Warning: The database defined as "test" will be erased and
21 9
 # re-generated from your development database when you run "rake".
22 10
 # Do not set this db to the same as development or production.
23 11
 test:
24
-  <<: *default
25
-  # database: db/test.sqlite3
26
-  database: chronobriq_test
12
+    <<: *default
13
+    database: chronobriq_test
14
+
15
+development:
16
+    <<: *default
17
+    database: chronobriq_development
27 18
 
28 19
 production:
29
-  <<: *default
30
-  # database: db/production.sqlite3
31
-  database: chronobriq_production
20
+    <<: *default
21
+    database: chronobriq_production

+ 5
- 3
config/routes.rb Wyświetl plik

@@ -3,12 +3,14 @@ Rails.application.routes.draw do
3 3
     namespace :v1 do
4 4
       resources :users
5 5
       resources :tokens, only: %i[create]
6
-      resources :teams
7
-      resources :memberships
6
+      resources :teams do
7
+        resources :memberships
8
+      end
9
+      resources :memberships, only: %i[index]
8 10
       resources :activities do
9 11
         resources :tasks
10 12
       end
11
-      resources :tasks
13
+      resources :tasks, only: %i[index]
12 14
     end
13 15
   end
14 16
 end

+ 15
- 0
docker-compose.yml Wyświetl plik

@@ -0,0 +1,15 @@
1
+version: "3"
2
+services:
3
+    chronobriq-api:
4
+        build: .
5
+        ports:
6
+            - "9000:9000"
7
+        depends_on:
8
+            - db
9
+    db:
10
+        image: postgres:12-alpine
11
+        volumes:
12
+            - database:/var/lib/postgresql/chronobriq-api
13
+
14
+volumes:
15
+    database:

+ 32
- 22
test/controllers/api/v1/memberships_controller_test.rb Wyświetl plik

@@ -10,48 +10,58 @@ class Api::V1::MembershipsControllerTest < ActionDispatch::IntegrationTest
10 10
   end
11 11
 
12 12
   # INDEX
13
-  test "should access Membership index" do
14
-    get api_v1_memberships_url,
13
+  test "should access Membership index - specifix team" do
14
+    get api_v1_team_memberships_url(@team),
15 15
     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
16 16
     as: :json
17 17
     assert_response :success
18
+
19
+    json_response = JSON.parse(self.response.body)
20
+    assert_equal @membership.member_id, json_response['data'][0]['attributes']['member_id']
18 21
   end
19 22
 
20
-  test "should forbid Membership index" do
23
+  test "should access Membership index - all teams" do
21 24
     get api_v1_memberships_url,
25
+    headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
26
+    as: :json
27
+    assert_response :success
28
+  end
29
+
30
+  test "should not access Membership index" do
31
+    get api_v1_team_memberships_url(@team),
22 32
     as: :json
23 33
     assert_response :forbidden
24 34
   end
25 35
 
26 36
   # SHOW
27 37
   test "should show Membership" do
28
-    get api_v1_memberships_url(@membership),
38
+    get api_v1_team_memberships_url(@team, @membership),
29 39
     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
30 40
     as: :json
31 41
     assert_response :success
32 42
   end
33 43
 
34 44
   test "should forbid show Membership" do
35
-    get api_v1_memberships_url(@membership),
45
+    get api_v1_team_memberships_url(@team, @membership),
36 46
     as: :json
37 47
     assert_response :forbidden
38 48
   end
39 49
 
40
-  # CREATE
41
-  # test "should create membership" do
42
-  #   assert_difference("Membership.count") do
43
-  #     post api_v1_memberships_url,
44
-  #     params: { membership: { team_id: @team.id, member_id: @user.id, can_edit: false } },
45
-  #     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
46
-  #     as: :json
47
-  #   end
48
-  #   assert_response :created
49
-  # end
50
+  #CREATE
51
+  test "should create membership" do
52
+    assert_difference("Membership.count") do
53
+      post api_v1_team_memberships_url(@team),
54
+      params: { membership: { can_edit: false, member_id: @user2, team_id: @team } },
55
+      headers: { Authorization: JsonWebToken.encode(user_id: @user2.id) }, 
56
+      as: :json
57
+    end
58
+    assert_response :created
59
+  end
50 60
 
51 61
   test "should forbid create membership" do
52 62
     assert_no_difference("Membership.count") do
53
-      post api_v1_memberships_url,
54
-      params: { membership: { team_id: @team.id, member_id: @user.id, can_edit: false } },
63
+      post api_v1_team_memberships_url(@team),
64
+      params: { membership: { can_edit: false } },
55 65
       as: :json
56 66
     end
57 67
     assert_response :forbidden
@@ -59,7 +69,7 @@ class Api::V1::MembershipsControllerTest < ActionDispatch::IntegrationTest
59 69
 
60 70
   # UPDATE
61 71
   test "should update membership" do
62
-    patch api_v1_membership_url(@membership),
72
+    patch api_v1_team_membership_url(@team, @membership),
63 73
     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
64 74
     params: { membership: { can_edit: true } },
65 75
     as: :json
@@ -67,14 +77,14 @@ class Api::V1::MembershipsControllerTest < ActionDispatch::IntegrationTest
67 77
   end
68 78
 
69 79
   test "should forbid update membership" do
70
-    patch api_v1_membership_url(@membership),
80
+    patch api_v1_team_membership_url(@team, @membership),
71 81
     params: { membership: { can_edit: true } },
72 82
     as: :json
73 83
     assert_response :forbidden
74 84
   end
75 85
 
76 86
   test "should forbid update read_only attributes - team_id" do
77
-    patch api_v1_membership_url(@membership),
87
+    patch api_v1_team_membership_url(@team, @membership),
78 88
     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
79 89
     params: { membership: { team_id: @team2.id, member_id: @user2.id } },
80 90
     as: :json
@@ -84,7 +94,7 @@ class Api::V1::MembershipsControllerTest < ActionDispatch::IntegrationTest
84 94
   # DESTROY
85 95
   test "should destroy membership" do
86 96
     assert_difference('Membership.count', -1) do
87
-      delete api_v1_membership_url(@membership), 
97
+      delete api_v1_team_membership_url(@team, @membership), 
88 98
       headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
89 99
       as: :json
90 100
     end
@@ -93,7 +103,7 @@ class Api::V1::MembershipsControllerTest < ActionDispatch::IntegrationTest
93 103
 
94 104
   test "should forbid destroy membership" do
95 105
     assert_no_difference('Membership.count') do
96
-      delete api_v1_membership_url(@membership), as: :json
106
+      delete api_v1_team_membership_url(@team, @membership), as: :json
97 107
     end
98 108
     assert_response :forbidden
99 109
   end

+ 3
- 3
test/controllers/api/v1/tasks_controller_test.rb Wyświetl plik

@@ -44,17 +44,17 @@ class Api::V1::TasksControllerTest < ActionDispatch::IntegrationTest
44 44
   test "should create task" do
45 45
     assert_difference("Task.count") do
46 46
       post api_v1_activity_tasks_url(@activity),
47
-      params: { task: { name: @task.name, description: @task.description, owner_id: @user, activity_id: @activity, start_time: DateTime.now } },
47
+      params: { task: { name: @task.name, description: @task.description, owner_id: @user, start_time: DateTime.now } },
48 48
       headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
49 49
       as: :json
50 50
     end
51 51
     assert_response :created
52 52
   end
53 53
 
54
-  test "should not create task" do
54
+  test "should not create task - not logged in" do
55 55
     assert_no_difference("Task.count") do
56 56
       post api_v1_activity_tasks_url(@activity),
57
-      params: { task: { name: @task.name, description: @task.description, owner_id: @user, activity_id: @activity } },
57
+      params: { task: { name: @task.name, description: @task.description, owner_id: @user } },
58 58
       as: :json
59 59
     end
60 60
     assert_response :forbidden

+ 0
- 5
test/fixtures/memberships.yml Wyświetl plik

@@ -8,8 +8,3 @@ one:
8 8
   team: one
9 9
   member: one
10 10
   can_edit: true
11
-
12
-two:
13
-  team: one
14
-  member: two
15
-  can_edit: false

Loading…
Anuluj
Zapisz