enju_purchase_request 0.1.1 → 0.2.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +3 -3
  3. data/app/controllers/concerns/enju_purchase_request/controller.rb +19 -0
  4. data/app/controllers/order_lists_controller.rb +13 -3
  5. data/app/controllers/orders_controller.rb +13 -3
  6. data/app/controllers/purchase_requests_controller.rb +15 -10
  7. data/app/models/concerns/enju_purchase_request/enju_user.rb +10 -0
  8. data/app/models/order.rb +3 -4
  9. data/app/models/order_list.rb +2 -2
  10. data/app/models/order_list_transition.rb +5 -4
  11. data/app/models/purchase_request.rb +7 -8
  12. data/app/policies/bookstore_policy.rb +23 -0
  13. data/app/policies/order_list_policy.rb +21 -0
  14. data/app/policies/order_policy.rb +21 -0
  15. data/app/policies/purchase_request_policy.rb +25 -0
  16. data/app/views/orders/index.html.erb +5 -3
  17. data/app/views/purchase_requests/_index.html.erb +7 -7
  18. data/app/views/purchase_requests/_index_order_list.html.erb +6 -4
  19. data/app/views/purchase_requests/show.html.erb +1 -1
  20. data/db/migrate/20160703190738_add_most_recent_to_order_list_transitions.rb +9 -0
  21. data/lib/enju_purchase_request/version.rb +1 -1
  22. data/lib/enju_purchase_request.rb +0 -25
  23. data/lib/tasks/enju_purchase_request_tasks.rake +8 -0
  24. data/spec/controllers/order_lists_controller_spec.rb +13 -11
  25. data/spec/controllers/orders_controller_spec.rb +9 -9
  26. data/spec/controllers/purchase_requests_controller_spec.rb +4 -4
  27. data/spec/dummy/app/controllers/application_controller.rb +7 -4
  28. data/spec/dummy/app/models/user.rb +2 -3
  29. data/spec/dummy/config/application.rb +7 -24
  30. data/spec/dummy/config/environments/development.rb +22 -18
  31. data/spec/dummy/config/environments/production.rb +46 -34
  32. data/spec/dummy/config/environments/test.rb +21 -14
  33. data/spec/dummy/db/migrate/149_create_message_templates.rb +18 -0
  34. data/spec/dummy/db/migrate/154_create_messages.rb +23 -0
  35. data/spec/dummy/db/migrate/20080819181903_create_message_requests.rb +18 -0
  36. data/spec/dummy/db/migrate/20081212151614_create_bookmark_stats.rb +0 -3
  37. data/spec/dummy/db/migrate/20110913115320_add_lft_and_rgt_to_message.rb +11 -0
  38. data/spec/dummy/db/migrate/20120125050502_add_depth_to_message.rb +6 -0
  39. data/spec/dummy/db/migrate/20140110122216_create_user_import_files.rb +1 -1
  40. data/spec/dummy/db/migrate/20140518111006_create_message_transitions.rb +18 -0
  41. data/spec/dummy/db/migrate/20140518135713_create_message_request_transitions.rb +18 -0
  42. data/spec/dummy/db/migrate/20140524074813_create_user_import_file_transitions.rb +5 -1
  43. data/spec/dummy/db/migrate/20140524135607_create_bookmark_stat_transitions.rb +5 -1
  44. data/spec/dummy/db/migrate/20140709113905_create_user_export_file_transitions.rb +5 -1
  45. data/spec/dummy/db/migrate/20140821151023_create_colors.rb +14 -0
  46. data/spec/dummy/db/migrate/20141013152011_add_missing_unique_indices.acts_as_taggable_on_engine.rb +20 -0
  47. data/spec/dummy/db/migrate/20141013152013_add_missing_taggable_index.acts_as_taggable_on_engine.rb +10 -0
  48. data/spec/dummy/db/migrate/20150506105356_add_error_message_to_user_import_result.rb +5 -0
  49. data/spec/dummy/db/migrate/20150924115059_create_withdraws.rb +13 -0
  50. data/spec/dummy/db/migrate/20151213070943_add_translation_table_to_library_group.rb +13 -0
  51. data/spec/dummy/db/migrate/20151213072705_add_footer_banner_to_library_group.rb +9 -0
  52. data/spec/dummy/db/migrate/20160610093229_add_html_snippet_to_library_group.rb +5 -0
  53. data/spec/dummy/db/migrate/20160627232219_add_most_recent_to_user_import_file_transitions.rb +9 -0
  54. data/spec/dummy/db/migrate/20160627232316_add_most_recent_to_user_export_file_transitions.rb +9 -0
  55. data/spec/dummy/db/migrate/20160703185015_add_most_recent_to_message_transitions.rb +9 -0
  56. data/spec/dummy/db/migrate/20160813191647_add_max_number_of_results_to_library_group.rb +5 -0
  57. data/spec/dummy/db/migrate/20160813191733_add_family_name_first_to_library_group.rb +5 -0
  58. data/spec/dummy/db/migrate/20160813192542_add_pub_year_facet_range_interval_to_library_group.rb +5 -0
  59. data/spec/dummy/db/migrate/20160813203039_add_user_id_to_library_group.rb +5 -0
  60. data/spec/dummy/db/migrate/20160814165332_add_most_recent_to_message_request_transitions.rb +9 -0
  61. data/spec/dummy/db/migrate/20160815045420_add_most_recent_to_bookmark_stat_transitions.rb +9 -0
  62. data/spec/dummy/db/schema.rb +123 -10
  63. data/spec/fixtures/library_groups.yml +1 -0
  64. data/spec/fixtures/order_list_transitions.yml +10 -6
  65. data/spec/fixtures/order_lists.yml +2 -3
  66. data/spec/fixtures/orders.yml +3 -4
  67. data/spec/fixtures/purchase_requests.yml +6 -7
  68. data/spec/models/order_list_spec.rb +3 -4
  69. data/spec/models/order_spec.rb +4 -6
  70. data/spec/models/purchase_request_spec.rb +7 -9
  71. data/spec/rails_helper.rb +53 -0
  72. data/spec/spec_helper.rb +82 -43
  73. data/spec/support/devise.rb +2 -2
  74. metadata +261 -194
  75. data/app/models/enju_purchase_request/ability.rb +0 -30
  76. data/lib/enju_purchase_request/user.rb +0 -14
  77. data/spec/dummy/app/models/ability.rb +0 -30
  78. data/spec/dummy/app/views/page/403.html.erb +0 -9
  79. data/spec/dummy/app/views/page/403.mobile.erb +0 -5
  80. data/spec/dummy/app/views/page/403.xml.erb +0 -4
  81. data/spec/dummy/app/views/page/404.html.erb +0 -9
  82. data/spec/dummy/app/views/page/404.mobile.erb +0 -5
  83. data/spec/dummy/app/views/page/404.xml.erb +0 -4
  84. data/spec/dummy/config/application.yml +0 -38
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2fc1305c5c75d6ff4de30d9b5cc02cabe80595d8
4
- data.tar.gz: 4b02362108242aef5a2b9c89f5385a7e19a1243d
3
+ metadata.gz: c9dbb79d1677349e2baac147f142a61dba3aa49f
4
+ data.tar.gz: 2976b93d9b6e8821334b243f553dd6d80518359a
5
5
  SHA512:
6
- metadata.gz: 0cc6e411c383bdf18939112eeb7826b6d1c179f62298e4f9c1e8e5a892aa80d24feb9c338b32c51a6f3343ff93ce9dc9c140dd5b6d17794e9a32e4efcd5c6e3a
7
- data.tar.gz: b57ee7d68df3cc461cc02b784330f267634f592eafbb5af58b2fce548925b444a987340d40610fec1df6977bd4c64f6ae785c95315f6f0cc442a4e29cefdfd31
6
+ metadata.gz: b03871bcea0ed5ad39b569e4fdc764e511d55a2163ca2bc541ef5dde25facdac100a50a058ddc70bafaaacfc81293a72fd52096c009840d22ad05b30b526e513
7
+ data.tar.gz: f4bbfed5aa655e9175eaa42cc1b876b3807ec0e9461f62246e1515f4eac6e3463e604d3d18de35663c72fd5944f7d54f4cbd1b2b58fc163c017638b0b6d27eb1
data/README.rdoc CHANGED
@@ -1,7 +1,7 @@
1
1
  = EnjuPurchaseRequest
2
- {<img src="https://travis-ci.org/next-l/enju_purchase_request.svg?branch=1.1" alt="Build Status" />}[https://travis-ci.org/next-l/enju_purchase_request]
3
- {<img src="https://coveralls.io/repos/next-l/enju_purchase_request/badge.svg?branch=1.1&service=github" alt="Coverage Status" />}[https://coveralls.io/github/next-l/enju_purchase_request?branch=1.1]
4
- {<img src="https://hakiri.io/github/next-l/enju_purchase_request/1.1.svg" alt="security" />}[https://hakiri.io/github/next-l/enju_purchase_request/1.1]
2
+ {<img src="https://travis-ci.org/next-l/enju_purchase_request.svg?branch=1.2" alt="Build Status" />}[https://travis-ci.org/next-l/enju_purchase_request]
3
+ {<img src="https://coveralls.io/repos/next-l/enju_purchase_request/badge.svg?branch=1.2&service=github" alt="Coverage Status" />}[https://coveralls.io/github/next-l/enju_purchase_request?branch=1.2]
4
+ {<img src="https://hakiri.io/github/next-l/enju_purchase_request/1.2.svg" alt="security" />}[https://hakiri.io/github/next-l/enju_purchase_request/1.2]
5
5
 
6
6
  This project rocks and uses MIT-LICENSE.
7
7
 
@@ -0,0 +1,19 @@
1
+ module EnjuPurchaseRequest
2
+ module Controller
3
+ private
4
+
5
+ def get_order_list
6
+ if params[:order_list_id]
7
+ @order_list = OrderList.find(params[:order_list_id])
8
+ authorize @order_list, :show?
9
+ end
10
+ end
11
+
12
+ def get_purchase_request
13
+ if params[:purchase_request_id]
14
+ @purchase_request = PurchaseRequest.find(params[:purchase_request_id])
15
+ authorize @purchase_request, :show?
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,7 +1,8 @@
1
1
  class OrderListsController < ApplicationController
2
- load_and_authorize_resource
3
- before_filter :prepare_options, only: [:new, :edit]
4
- before_filter :get_bookstore, only: :index
2
+ before_action :set_order_list, only: [:show, :edit, :update, :destroy]
3
+ before_action :check_policy, only: [:index, :new, :create]
4
+ before_action :prepare_options, only: [:new, :edit]
5
+ before_action :get_bookstore, only: :index
5
6
 
6
7
  # GET /order_lists
7
8
  # GET /order_lists.json
@@ -97,6 +98,15 @@ class OrderListsController < ApplicationController
97
98
  end
98
99
 
99
100
  private
101
+ def set_order_list
102
+ @order_list = OrderList.find(params[:id])
103
+ authorize @order_list
104
+ end
105
+
106
+ def check_policy
107
+ authorize OrderList
108
+ end
109
+
100
110
  def order_list_params
101
111
  params.require(:order_list).permit(
102
112
  :user_id, :bookstore_id, :title, :note, :ordered_at, :edit_mode
@@ -1,7 +1,8 @@
1
1
  class OrdersController < ApplicationController
2
- load_and_authorize_resource
3
- before_filter :get_order_list
4
- before_filter :get_purchase_request
2
+ before_action :set_order, only: [:show, :edit, :update, :destroy]
3
+ before_action :check_policy, only: [:index, :new, :create]
4
+ before_action :get_order_list
5
+ before_action :get_purchase_request
5
6
 
6
7
  # GET /orders
7
8
  # GET /orders.json
@@ -128,6 +129,15 @@ class OrdersController < ApplicationController
128
129
  end
129
130
 
130
131
  private
132
+ def set_order
133
+ @order = Order.find(params[:id])
134
+ authorize @order
135
+ end
136
+
137
+ def check_policy
138
+ authorize Order
139
+ end
140
+
131
141
  def order_params
132
142
  params.require(:order).permit(:order_list_id, :purchase_request_id)
133
143
  end
@@ -1,11 +1,10 @@
1
1
  class PurchaseRequestsController < ApplicationController
2
- load_and_authorize_resource except: :index
3
- authorize_resource only: :index
4
- before_filter :get_user
5
- before_filter :get_order_list
6
- before_filter :store_page, only: :index
7
- after_filter :solr_commit, only: [:create, :update, :destroy]
8
- after_filter :convert_charset, only: :index
2
+ before_action :store_page, only: :index
3
+ before_action :set_purchase_request, only: [:show, :edit, :update, :destroy]
4
+ before_action :check_policy, only: [:index, :new, :create]
5
+ before_action :get_user
6
+ before_action :get_order_list
7
+ after_action :convert_charset, only: :index
9
8
 
10
9
  # GET /purchase_requests
11
10
  # GET /purchase_requests.json
@@ -23,9 +22,6 @@ class PurchaseRequestsController < ApplicationController
23
22
 
24
23
  user = @user
25
24
  unless current_user.has_role?('Librarian')
26
- if @order_list
27
- access_denied; return
28
- end
29
25
  if user and user != current_user
30
26
  access_denied; return
31
27
  end
@@ -145,6 +141,15 @@ class PurchaseRequestsController < ApplicationController
145
141
  end
146
142
 
147
143
  private
144
+ def set_purchase_request
145
+ @purchase_request = PurchaseRequest.find(params[:id])
146
+ authorize @purchase_request
147
+ end
148
+
149
+ def check_policy
150
+ authorize PurchaseRequest
151
+ end
152
+
148
153
  def purchase_request_params
149
154
  params.fetch(:purchase_request, {}).permit(
150
155
  :title, :author, :publisher, :isbn, :price, :url, :note, :pub_date
@@ -0,0 +1,10 @@
1
+ module EnjuPurchaseRequest
2
+ module EnjuUser
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_many :purchase_requests
7
+ has_many :order_lists
8
+ end
9
+ end
10
+ end
data/app/models/order.rb CHANGED
@@ -26,8 +26,7 @@ end
26
26
  # order_list_id :integer not null
27
27
  # purchase_request_id :integer not null
28
28
  # position :integer
29
- # state :string(255)
30
- # created_at :datetime not null
31
- # updated_at :datetime not null
29
+ # state :string
30
+ # created_at :datetime
31
+ # updated_at :datetime
32
32
  #
33
-
@@ -61,6 +61,6 @@ end
61
61
  # note :text
62
62
  # ordered_at :datetime
63
63
  # deleted_at :datetime
64
- # created_at :datetime not null
65
- # updated_at :datetime not null
64
+ # created_at :datetime
65
+ # updated_at :datetime
66
66
  #
@@ -10,10 +10,11 @@ end
10
10
  # Table name: order_list_transitions
11
11
  #
12
12
  # id :integer not null, primary key
13
- # to_state :string(255)
14
- # metadata :text default("{}")
13
+ # to_state :string
14
+ # metadata :text default({})
15
15
  # sort_key :integer
16
16
  # order_list_id :integer
17
- # created_at :datetime not null
18
- # updated_at :datetime not null
17
+ # created_at :datetime
18
+ # updated_at :datetime
19
+ # most_recent :boolean
19
20
  #
@@ -14,7 +14,7 @@ class PurchaseRequest < ActiveRecord::Base
14
14
  after_destroy :index!
15
15
  before_save :set_date_of_publication
16
16
 
17
- normalize_attributes :url, :pub_date
17
+ strip_attributes only: [:url, :pub_date]
18
18
 
19
19
  searchable do
20
20
  text :title, :author, :publisher, :url
@@ -74,17 +74,16 @@ end
74
74
  # title :text not null
75
75
  # author :text
76
76
  # publisher :text
77
- # isbn :string(255)
77
+ # isbn :string
78
78
  # date_of_publication :datetime
79
79
  # price :integer
80
- # url :string(255)
80
+ # url :string
81
81
  # note :text
82
82
  # accepted_at :datetime
83
83
  # denied_at :datetime
84
- # created_at :datetime not null
85
- # updated_at :datetime not null
84
+ # created_at :datetime
85
+ # updated_at :datetime
86
86
  # deleted_at :datetime
87
- # state :string(255)
88
- # pub_date :string(255)
87
+ # state :string
88
+ # pub_date :string
89
89
  #
90
-
@@ -0,0 +1,23 @@
1
+ class BookstorePolicy < ApplicationPolicy
2
+ def index?
3
+ true if user.try(:has_role?, 'Librarian')
4
+ end
5
+
6
+ def show?
7
+ true if user.try(:has_role?, 'Librarian')
8
+ end
9
+
10
+ def create?
11
+ true if user.try(:has_role?, 'Administrator')
12
+ end
13
+
14
+ def update?
15
+ true if user.try(:has_role?, 'Administrator')
16
+ end
17
+
18
+ def destroy?
19
+ if user.try(:has_role?, 'Administrator')
20
+ true if record.items.empty? and record.order_lists.empty?
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ class OrderListPolicy < ApplicationPolicy
2
+ def index?
3
+ true if user.try(:has_role?, 'Librarian')
4
+ end
5
+
6
+ def show?
7
+ true if user.try(:has_role?, 'Librarian')
8
+ end
9
+
10
+ def create?
11
+ true if user.try(:has_role?, 'Librarian')
12
+ end
13
+
14
+ def update?
15
+ true if user.try(:has_role?, 'Librarian')
16
+ end
17
+
18
+ def destroy?
19
+ true if user.try(:has_role?, 'Librarian')
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ class OrderPolicy < ApplicationPolicy
2
+ def index?
3
+ true if user.try(:has_role?, 'Librarian')
4
+ end
5
+
6
+ def show?
7
+ true if user.try(:has_role?, 'Librarian')
8
+ end
9
+
10
+ def create?
11
+ true if user.try(:has_role?, 'Librarian')
12
+ end
13
+
14
+ def update?
15
+ true if user.try(:has_role?, 'Librarian')
16
+ end
17
+
18
+ def destroy?
19
+ true if user.try(:has_role?, 'Librarian')
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ class PurchaseRequestPolicy < ApplicationPolicy
2
+ def index?
3
+ true if user.try(:has_role?, 'User')
4
+ end
5
+
6
+ def show?
7
+ if user.try(:has_role?, 'Librarian')
8
+ true
9
+ elsif user.try(:has_role?, 'User')
10
+ true if record.user == user
11
+ end
12
+ end
13
+
14
+ def create?
15
+ true if user.try(:has_role?, 'User')
16
+ end
17
+
18
+ def update?
19
+ show?
20
+ end
21
+
22
+ def destroy?
23
+ show?
24
+ end
25
+ end
@@ -16,9 +16,11 @@
16
16
  <td><%= link_to order.purchase_request.title, purchase_request_path(order.purchase_request) -%></td>
17
17
  <td><%= l(order.updated_at) -%></td>
18
18
  <td>
19
- <%- if can? :delete, order -%>
20
- <%= link_to t('page.show'), order_path(order) -%>
19
+ <%= link_to t('page.show'), order_path(order) -%>
20
+ <%- if policy(order).update? -%>
21
21
  <%= link_to t('page.edit'), edit_order_path(order) -%>
22
+ <%- end -%>
23
+ <%- if policy(order).destroy? -%>
22
24
  <%= link_to t('page.destroy'), order_path(order), data: {confirm: t('page.are_you_sure')}, method: :delete -%>
23
25
  <%- end -%>
24
26
  </td>
@@ -33,7 +35,7 @@
33
35
 
34
36
  <div id="submenu" class="ui-corner-all ui-widget-content">
35
37
  <ul>
36
- <%- if can? :create, Order -%>
38
+ <%- if policy(Order).create? -%>
37
39
  <li><%= link_to t('page.new', model: t('activerecord.models.order')), new_order_path -%></li>
38
40
  <%- end -%>
39
41
  </ul>
@@ -34,10 +34,10 @@
34
34
  </td>
35
35
  <td><%= purchase_request.price -%></td>
36
36
  <td>
37
- <%- if can? :update, purchase_request %>
37
+ <%- if policy(purchase_request).update? %>
38
38
  <%= link_to t('page.edit'), edit_purchase_request_path(purchase_request) -%>
39
- <%- end -%>
40
- <%- if can? :delete, purchase_request %>
39
+ <% end %>
40
+ <%- if policy(purchase_request).destroy? %>
41
41
  <%= link_to t('page.destroy'), purchase_request, data: {confirm: t('page.are_you_sure')}, method: :delete -%>
42
42
  <%- end -%>
43
43
  </td>
@@ -69,14 +69,14 @@
69
69
  </ul>
70
70
  <p>
71
71
  <%- if @user -%>
72
- <%= link_to (image_tag 'icons/feed.png', size: '16x16', alt: t('page.feed'), class: 'icon'), purchase_requests_path(user_id: @user.username, format: :rss, locale: @locale.to_s) -%>
72
+ <%= link_to image_tag('icons/feed.png', size: '16x16', class: 'enju_icon', alt: t('page.feed')), purchase_requests_path(user_id: @user.username, format: :rss, locale: @locale.to_s) -%>
73
73
  (<%= link_to 'RSS', purchase_requests_path(user_id: @user.username, format: :rss, locale: @locale.to_s) -%>)
74
- <%= link_to (image_tag 'icons/page_white_excel.png', size: '16x16', alt: 'TSV', class: 'icon'), purchase_requests_path(user_id: @user.username, format: :txt) -%>
74
+ <%= link_to image_tag('icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), purchase_requests_path(user_id: @user.username, format: :txt) -%>
75
75
  (<%= link_to 'TSV', purchase_requests_path(user_id: @user.username, format: :txt) -%>)
76
76
  <%- else -%>
77
- <%= link_to (image_tag 'icons/feed.png', size: '16x16', alt: t('page.feed'), class: 'icon'), purchase_requests_path(format: :rss, locale: @locale.to_s) -%>
77
+ <%= link_to image_tag('icons/feed.png', size: '16x16', class: 'enju_icon', alt: t('page.feed')), purchase_requests_path(format: :rss, locale: @locale.to_s) -%>
78
78
  (<%= link_to 'RSS', purchase_requests_path(format: :rss, locale: @locale.to_s) -%>)
79
- <%= link_to (image_tag 'icons/page_white_excel.png', size: '16x16', alt: 'TSV', class: 'icon'), purchase_requests_path(format: :txt) -%>
79
+ <%= link_to image_tag('icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), purchase_requests_path(format: :txt) -%>
80
80
  (<%= link_to 'TSV', purchase_requests_path(format: :txt) -%>)
81
81
  <%- end -%>
82
82
  </p>
@@ -39,8 +39,10 @@
39
39
  </td>
40
40
  <td><%= purchase_request.price -%></td>
41
41
  <td>
42
- <%= link_to t('page.edit'), edit_purchase_request_path(purchase_request) -%>
43
- <%- if can? :delete, purchase_request -%>
42
+ <%- if policy(purchase_request).update? -%>
43
+ <%= link_to t('page.edit'), edit_purchase_request_path(purchase_request) -%>
44
+ <% end %>
45
+ <%- if policy(purchase_request).destroy? -%>
44
46
  <%- if params[:mode] == "add" -%>
45
47
  <%= link_to t('page.add'), new_purchase_request_path(order_list_id: @order_list, purchase_request_id: purchase_request.id, mode: 'add') -%>
46
48
  <%- else -%>
@@ -67,9 +69,9 @@
67
69
  </ul>
68
70
  <% if @order_list.ordered? %>
69
71
  <p>
70
- <%= link_to (image_tag 'icons/feed.png', size: '16x16', alt: t('page.feed'), class: 'icon'), purchase_requests_path(order_list_id: @order_list.id, format: :rss) -%>
72
+ <%= link_to image_tag('icons/feed.png', size: '16x16', class: 'enju_icon', alt: t('page.feed')), purchase_requests_path(order_list_id: @order_list.id, format: :rss) -%>
71
73
  (<%= link_to 'RSS', purchase_requests_path(order_list_id: @order_list.id, format: :rss) -%>)
72
- <%= link_to (image_tag 'icons/page_white_excel.png', size: '16x16', alt: 'TSV', class: 'icon'), purchase_requests_path(order_list_id: @order_list.id, format: :txt) -%>
74
+ <%= link_to image_tag('icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), purchase_requests_path(order_list_id: @order_list.id, format: :txt) -%>
73
75
  (<%= link_to 'TSV', purchase_requests_path(order_list_id: @order_list.id, format: :txt) -%>)
74
76
  </p>
75
77
  <% end %>
@@ -81,7 +81,7 @@
81
81
 
82
82
  <div id="submenu" class="ui-corner-all ui-widget-content">
83
83
  <ul>
84
- <% if can? :update, Order %>
84
+ <% if policy(Order).create? %>
85
85
  <%- if @purchase_request.order_list -%>
86
86
  <li><%= link_to t('purchase_request.remove_from_order_list'), order_path(@purchase_request.order, order_list_id: @purchase_request.order_list.id), method: :delete, data: {confirm: t('page.are_you_sure')} -%></li>
87
87
  <%- else -%>
@@ -0,0 +1,9 @@
1
+ class AddMostRecentToOrderListTransitions < ActiveRecord::Migration
2
+ def up
3
+ add_column :order_list_transitions, :most_recent, :boolean, null: true
4
+ end
5
+
6
+ def down
7
+ remove_column :order_list_transitions, :most_recent
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module EnjuPurchaseRequest
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0.beta.2"
3
3
  end
@@ -1,30 +1,5 @@
1
1
  require "enju_purchase_request/engine"
2
2
  require "enju_purchase_request/bookmark_url"
3
- require "enju_purchase_request/user"
4
3
 
5
4
  module EnjuPurchaseRequest
6
- def self.included(base)
7
- base.extend(ClassMethods)
8
- end
9
-
10
- module ClassMethods
11
- def enju_purchase_request
12
- include EnjuPurchaseRequest::InstanceMethods
13
- end
14
- end
15
-
16
- module InstanceMethods
17
- private
18
-
19
- def get_order_list
20
- @order_list = OrderList.find(params[:order_list_id]) if params[:order_list_id]
21
- end
22
-
23
- def get_purchase_request
24
- @purchase_request = PurchaseRequest.find(params[:purchase_request_id]) if params[:purchase_request_id]
25
- end
26
- end
27
5
  end
28
-
29
- ActionController::Base.send(:include, EnjuPurchaseRequest)
30
- ActiveRecord::Base.send :include, EnjuPurchaseRequest::PurchaseRequestUser
@@ -2,3 +2,11 @@
2
2
  # task :enju_purchase_request do
3
3
  # # Task goes here
4
4
  # end
5
+ namespace :enju_purchase_request do
6
+ desc "upgrade enju_purchase_request"
7
+ task :upgrade => :environment do
8
+ Rake::Task['statesman:backfill_most_recent'].invoke('OrderList')
9
+ puts 'enju_purchase_request: The upgrade completed successfully.'
10
+ end
11
+ end
12
+
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'rails_helper'
2
2
  require 'sunspot/rails/spec_helper'
3
3
 
4
4
  describe OrderListsController do
@@ -35,14 +35,14 @@ describe OrderListsController do
35
35
 
36
36
  it "assigns empty as @order_lists" do
37
37
  get :index
38
- assigns(:order_lists).should be_empty
38
+ assigns(:order_lists).should be_nil
39
39
  end
40
40
  end
41
41
 
42
42
  describe "When not logged in" do
43
43
  it "assigns empty as @order_lists" do
44
44
  get :index
45
- assigns(:order_lists).should be_empty
45
+ assigns(:order_lists).should be_nil
46
46
  end
47
47
  end
48
48
  end
@@ -101,7 +101,8 @@ describe OrderListsController do
101
101
 
102
102
  it "assigns the requested order_list as @order_list" do
103
103
  get :new
104
- assigns(:order_list).should_not be_valid
104
+ assigns(:order_list).should be_nil
105
+ response.should be_success
105
106
  end
106
107
  end
107
108
 
@@ -112,7 +113,8 @@ describe OrderListsController do
112
113
 
113
114
  it "assigns the requested order_list as @order_list" do
114
115
  get :new
115
- assigns(:order_list).should_not be_valid
116
+ assigns(:order_list).should be_nil
117
+ response.should be_success
116
118
  end
117
119
  end
118
120
 
@@ -123,7 +125,7 @@ describe OrderListsController do
123
125
 
124
126
  it "should not assign the requested order_list as @order_list" do
125
127
  get :new
126
- assigns(:order_list).should_not be_valid
128
+ assigns(:order_list).should be_nil
127
129
  response.should be_forbidden
128
130
  end
129
131
  end
@@ -131,7 +133,7 @@ describe OrderListsController do
131
133
  describe "When not logged in" do
132
134
  it "should not assign the requested order_list as @order_list" do
133
135
  get :new
134
- assigns(:order_list).should_not be_valid
136
+ assigns(:order_list).should be_nil
135
137
  response.should redirect_to(new_user_session_url)
136
138
  end
137
139
  end
@@ -257,7 +259,7 @@ describe OrderListsController do
257
259
  describe "with valid params" do
258
260
  it "assigns a newly created order_list as @order_list" do
259
261
  post :create, :order_list => @attrs
260
- assigns(:order_list).should be_valid
262
+ assigns(:order_list).should be_nil
261
263
  end
262
264
 
263
265
  it "should be forbidden" do
@@ -269,7 +271,7 @@ describe OrderListsController do
269
271
  describe "with invalid params" do
270
272
  it "assigns a newly created but unsaved order_list as @order_list" do
271
273
  post :create, :order_list => @invalid_attrs
272
- assigns(:order_list).should_not be_valid
274
+ assigns(:order_list).should be_nil
273
275
  end
274
276
 
275
277
  it "should be forbidden" do
@@ -283,7 +285,7 @@ describe OrderListsController do
283
285
  describe "with valid params" do
284
286
  it "assigns a newly created order_list as @order_list" do
285
287
  post :create, :order_list => @attrs
286
- assigns(:order_list).should be_valid
288
+ assigns(:order_list).should be_nil
287
289
  end
288
290
 
289
291
  it "should be forbidden" do
@@ -295,7 +297,7 @@ describe OrderListsController do
295
297
  describe "with invalid params" do
296
298
  it "assigns a newly created but unsaved order_list as @order_list" do
297
299
  post :create, :order_list => @invalid_attrs
298
- assigns(:order_list).should_not be_valid
300
+ assigns(:order_list).should be_nil
299
301
  end
300
302
 
301
303
  it "should be forbidden" do
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'rails_helper'
2
2
  require 'sunspot/rails/spec_helper'
3
3
 
4
4
  describe OrdersController do
@@ -39,7 +39,7 @@ describe OrdersController do
39
39
 
40
40
  it "should be forbidden" do
41
41
  get :index
42
- assigns(:orders).should be_empty
42
+ assigns(:orders).should be_nil
43
43
  response.should be_forbidden
44
44
  end
45
45
  end
@@ -47,7 +47,7 @@ describe OrdersController do
47
47
  describe "When not logged in" do
48
48
  it "assigns all orders as @orders" do
49
49
  get :index
50
- assigns(:orders).should be_empty
50
+ assigns(:orders).should be_nil
51
51
  response.should redirect_to(new_user_session_url)
52
52
  end
53
53
  end
@@ -143,7 +143,7 @@ describe OrdersController do
143
143
 
144
144
  it "should not assign the requested order as @order" do
145
145
  get :new, :order_list_id => 1, :purchase_request_id => 1
146
- assigns(:order).should_not be_valid
146
+ assigns(:order).should be_nil
147
147
  response.should be_forbidden
148
148
  end
149
149
  end
@@ -151,7 +151,7 @@ describe OrdersController do
151
151
  describe "When not logged in" do
152
152
  it "should not assign the requested order as @order" do
153
153
  get :new, :order_list_id => 1, :purchase_request_id => 1
154
- assigns(:order).should_not be_valid
154
+ assigns(:order).should be_nil
155
155
  response.should redirect_to(new_user_session_url)
156
156
  end
157
157
  end
@@ -277,7 +277,7 @@ describe OrdersController do
277
277
  describe "with valid params" do
278
278
  it "assigns a newly created order as @order" do
279
279
  post :create, :order => @attrs
280
- assigns(:order).should be_valid
280
+ assigns(:order).should be_nil
281
281
  end
282
282
 
283
283
  it "should be forbidden" do
@@ -289,7 +289,7 @@ describe OrdersController do
289
289
  describe "with invalid params" do
290
290
  it "assigns a newly created but unsaved order as @order" do
291
291
  post :create, :order => @invalid_attrs
292
- assigns(:order).should_not be_valid
292
+ assigns(:order).should be_nil
293
293
  end
294
294
 
295
295
  it "should be forbidden" do
@@ -303,7 +303,7 @@ describe OrdersController do
303
303
  describe "with valid params" do
304
304
  it "assigns a newly created order as @order" do
305
305
  post :create, :order => @attrs
306
- assigns(:order).should be_valid
306
+ assigns(:order).should be_nil
307
307
  end
308
308
 
309
309
  it "should be forbidden" do
@@ -315,7 +315,7 @@ describe OrdersController do
315
315
  describe "with invalid params" do
316
316
  it "assigns a newly created but unsaved order as @order" do
317
317
  post :create, :order => @invalid_attrs
318
- assigns(:order).should_not be_valid
318
+ assigns(:order).should be_nil
319
319
  end
320
320
 
321
321
  it "should be forbidden" do