Browse Source

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

nas 2 years ago
parent
commit
b46912ab42

+ 4
- 0
.dockerignore View File

1
+erd.pdf
2
+.git
3
+.gitignore
4
+.gitattributes

+ 65
- 0
Dockerfile View File

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 View File

16
 3. `rails server` pour lancer un serveur local de développement sur le port 3000
16
 3. `rails server` pour lancer un serveur local de développement sur le port 3000
17
 
17
 
18
 ### 2. Endpoints
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
 ## Tests
21
 ## Tests
22
 
22
 
70
 
70
 
71
 ### Routes
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 View File

3
   before_action :check_login
3
   before_action :check_login
4
 
4
 
5
   def index
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
   end
11
   end
8
-
12
+  
9
   def show
13
   def show
10
     render json: MembershipSerializer.new(@membership).serializable_hash.to_json
14
     render json: MembershipSerializer.new(@membership).serializable_hash.to_json
11
   end
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
     if membership.save
21
     if membership.save
20
       render json: MembershipSerializer.new(membership).serializable_hash.to_json, status: :created
22
       render json: MembershipSerializer.new(membership).serializable_hash.to_json, status: :created
21
     else
23
     else
25
 
27
 
26
   def update
28
   def update
27
     if params[:membership][:can_edit] 
29
     if params[:membership][:can_edit] 
28
-      if @membership.update(memberships_params)
30
+      if @membership.update(membership_params)
29
         render json: MembershipSerializer.new(@membership).serializable_hash.to_json, status: :ok
31
         render json: MembershipSerializer.new(@membership).serializable_hash.to_json, status: :ok
30
       else
32
       else
31
         render json: @membership.errors, status: :unprocessable_entity
33
         render json: @membership.errors, status: :unprocessable_entity
42
 
44
 
43
   private
45
   private
44
 
46
 
45
-  def memberships_params
47
+  def membership_params
46
     params.require(:membership).permit(:can_edit)
48
     params.require(:membership).permit(:can_edit)
47
   end
49
   end
48
   
50
   

+ 1
- 1
app/models/activity.rb View File

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

+ 0
- 3
app/models/membership.rb View File

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

+ 3
- 3
app/models/task.rb View File

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

+ 13
- 23
config/database.yml View File

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
 default: &default
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
 # Warning: The database defined as "test" will be erased and
8
 # Warning: The database defined as "test" will be erased and
21
 # re-generated from your development database when you run "rake".
9
 # re-generated from your development database when you run "rake".
22
 # Do not set this db to the same as development or production.
10
 # Do not set this db to the same as development or production.
23
 test:
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
 production:
19
 production:
29
-  <<: *default
30
-  # database: db/production.sqlite3
31
-  database: chronobriq_production
20
+    <<: *default
21
+    database: chronobriq_production

+ 5
- 3
config/routes.rb View File

3
     namespace :v1 do
3
     namespace :v1 do
4
       resources :users
4
       resources :users
5
       resources :tokens, only: %i[create]
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
       resources :activities do
10
       resources :activities do
9
         resources :tasks
11
         resources :tasks
10
       end
12
       end
11
-      resources :tasks
13
+      resources :tasks, only: %i[index]
12
     end
14
     end
13
   end
15
   end
14
 end
16
 end

+ 15
- 0
docker-compose.yml View File

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 View File

10
   end
10
   end
11
 
11
 
12
   # INDEX
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
     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
15
     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
16
     as: :json
16
     as: :json
17
     assert_response :success
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
   end
21
   end
19
 
22
 
20
-  test "should forbid Membership index" do
23
+  test "should access Membership index - all teams" do
21
     get api_v1_memberships_url,
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
     as: :json
32
     as: :json
23
     assert_response :forbidden
33
     assert_response :forbidden
24
   end
34
   end
25
 
35
 
26
   # SHOW
36
   # SHOW
27
   test "should show Membership" do
37
   test "should show Membership" do
28
-    get api_v1_memberships_url(@membership),
38
+    get api_v1_team_memberships_url(@team, @membership),
29
     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
39
     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
30
     as: :json
40
     as: :json
31
     assert_response :success
41
     assert_response :success
32
   end
42
   end
33
 
43
 
34
   test "should forbid show Membership" do
44
   test "should forbid show Membership" do
35
-    get api_v1_memberships_url(@membership),
45
+    get api_v1_team_memberships_url(@team, @membership),
36
     as: :json
46
     as: :json
37
     assert_response :forbidden
47
     assert_response :forbidden
38
   end
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
   test "should forbid create membership" do
61
   test "should forbid create membership" do
52
     assert_no_difference("Membership.count") do
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
       as: :json
65
       as: :json
56
     end
66
     end
57
     assert_response :forbidden
67
     assert_response :forbidden
59
 
69
 
60
   # UPDATE
70
   # UPDATE
61
   test "should update membership" do
71
   test "should update membership" do
62
-    patch api_v1_membership_url(@membership),
72
+    patch api_v1_team_membership_url(@team, @membership),
63
     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
73
     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
64
     params: { membership: { can_edit: true } },
74
     params: { membership: { can_edit: true } },
65
     as: :json
75
     as: :json
67
   end
77
   end
68
 
78
 
69
   test "should forbid update membership" do
79
   test "should forbid update membership" do
70
-    patch api_v1_membership_url(@membership),
80
+    patch api_v1_team_membership_url(@team, @membership),
71
     params: { membership: { can_edit: true } },
81
     params: { membership: { can_edit: true } },
72
     as: :json
82
     as: :json
73
     assert_response :forbidden
83
     assert_response :forbidden
74
   end
84
   end
75
 
85
 
76
   test "should forbid update read_only attributes - team_id" do
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
     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
88
     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) }, 
79
     params: { membership: { team_id: @team2.id, member_id: @user2.id } },
89
     params: { membership: { team_id: @team2.id, member_id: @user2.id } },
80
     as: :json
90
     as: :json
84
   # DESTROY
94
   # DESTROY
85
   test "should destroy membership" do
95
   test "should destroy membership" do
86
     assert_difference('Membership.count', -1) do
96
     assert_difference('Membership.count', -1) do
87
-      delete api_v1_membership_url(@membership), 
97
+      delete api_v1_team_membership_url(@team, @membership), 
88
       headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
98
       headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
89
       as: :json
99
       as: :json
90
     end
100
     end
93
 
103
 
94
   test "should forbid destroy membership" do
104
   test "should forbid destroy membership" do
95
     assert_no_difference('Membership.count') do
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
     end
107
     end
98
     assert_response :forbidden
108
     assert_response :forbidden
99
   end
109
   end

+ 3
- 3
test/controllers/api/v1/tasks_controller_test.rb View File

44
   test "should create task" do
44
   test "should create task" do
45
     assert_difference("Task.count") do
45
     assert_difference("Task.count") do
46
       post api_v1_activity_tasks_url(@activity),
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
       headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
48
       headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
49
       as: :json
49
       as: :json
50
     end
50
     end
51
     assert_response :created
51
     assert_response :created
52
   end
52
   end
53
 
53
 
54
-  test "should not create task" do
54
+  test "should not create task - not logged in" do
55
     assert_no_difference("Task.count") do
55
     assert_no_difference("Task.count") do
56
       post api_v1_activity_tasks_url(@activity),
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
       as: :json
58
       as: :json
59
     end
59
     end
60
     assert_response :forbidden
60
     assert_response :forbidden

+ 0
- 5
test/fixtures/memberships.yml View File

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

Loading…
Cancel
Save