nps_surveys 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96c18ed076fc3d97e8c37fa45a7e4d8872430761
4
- data.tar.gz: 4ca9481c8c4946c2e88d26c60b55471983ab22d7
3
+ metadata.gz: 7e2e2fcac122892bc7f86fcbdaca1b277dbfe04c
4
+ data.tar.gz: 18093e363ec7a95c8e34c16e710fec2a34f95c9d
5
5
  SHA512:
6
- metadata.gz: 25357069abcf9e1d0e9da5fc49a459b096bbea57d8a994728546685139cb76e1f890da8dcadf07d541b56a24deef0810d2555a964833b95142916101bb0e9c3e
7
- data.tar.gz: 8b3d5fc92f99dc70f745462170e4ced03cefcba71eb5549e9c95418cf1e4a325f17b899db80058217dcfe5337b76c764d3117bed5261b272bd6b23e7b690ff9c
6
+ metadata.gz: 235d91f2cd04c163ffd32bd5aa901668c3a338e9b6e4a226b90ec4f50283d0da221aec69963e51e2bda3f5ad9f1de2c3730776bd0e4dcc8140bccfda9bac49ef
7
+ data.tar.gz: 5879a443a88c9a784a645ebf9cf9f6b65099e285deaa860685798a87d2ca8dcb553d5d6dc87c89fd1640732d30a5aaa5e90016f09f4aa2ccfd805a067ff8562d
@@ -1,7 +1,7 @@
1
- module NpsSurveys
1
+ module NPSSurveys
2
2
  module ApiInternal
3
3
 
4
- class ResponsesController < NpsSurveys.controller_parent_class
4
+ class ResponsesController < NPSSurveys.controller_parent_class
5
5
  def create
6
6
  response = create_survey_response
7
7
 
@@ -15,7 +15,7 @@ module NpsSurveys
15
15
  end
16
16
 
17
17
  def index
18
- responses = ::NpsSurveys::Response.where(user_id: NpsSurveys.current_user.call.id).map do |response|
18
+ responses = ::NPSSurveys::Response.where(user_id: NPSSurveys.current_user.call.id).map do |response|
19
19
  ResponseSerializer.new(response).to_json
20
20
  end
21
21
 
@@ -25,8 +25,8 @@ module NpsSurveys
25
25
  private
26
26
 
27
27
  def create_survey_response
28
- response = ::NpsSurveys::Response.new
29
- response.user_id = NpsSurveys.current_user.call.id
28
+ response = ::NPSSurveys::Response.new
29
+ response.user_id = NPSSurveys.current_user.call.id
30
30
  response.score = params[:score],
31
31
  response.feedback = params[:feedback],
32
32
  response.survey = params[:survey]
@@ -0,0 +1,18 @@
1
+ class AppException::UnprocessableEntity < AppException::Base
2
+ attr_accessor :object
3
+
4
+ # TODO: Deprecate second param
5
+ def initialize(object = nil, message = nil)
6
+ @object = object
7
+ super(message)
8
+ end
9
+
10
+ def body
11
+ JSON.generate(
12
+ error: {
13
+ message: 'Unprocessable Entity',
14
+ errors: errors || { message: message }
15
+ }
16
+ )
17
+ end
18
+ end
@@ -1,7 +1,5 @@
1
- module NpsSurveys
1
+ module NPSSurveys
2
2
  class Response < ActiveRecord::Base
3
- self.table_name = 'surveys_responses'
4
-
5
3
  validates :survey, presence: true
6
4
  validates :user_id, presence: true
7
5
  end
@@ -1,4 +1,4 @@
1
- module NpsSurveys
1
+ module NPSSurveys
2
2
  class ResponseSerializer
3
3
  def initialize(response)
4
4
  @response = response
@@ -1,5 +1,5 @@
1
- NpsSurveys.controller_parent_class = ::ApplicationController
2
- NpsSurveys.route_namespace = :api_internal
3
- NpsSurveys.route_path = 'api/internal'
4
- NpsSurveys.route_scope = 'nps_surveys'
5
- NpsSurveys.current_user = lambda { self.current_user }
1
+ NPSSurveys.controller_parent_class = ::ApplicationController
2
+ NPSSurveys.route_namespace = :api_internal
3
+ NPSSurveys.route_path = 'api/internal'
4
+ NPSSurveys.route_scope = 'nps_surveys'
5
+ NPSSurveys.current_user = lambda { self.current_user }
@@ -1,3 +1,3 @@
1
1
  Rails.application.routes do
2
- mount NpsSurveys::Engine, at: '/'
2
+ mount NPSSurveys::Engine, at: '/'
3
3
  end
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
- NpsSurveys::Engine.routes.draw do
2
- namespace NpsSurveys.route_namespace, path: NpsSurveys.route_path do
3
- scope NpsSurveys.route_scope do
1
+ NPSSurveys::Engine.routes.draw do
2
+ namespace NPSSurveys.route_namespace, path: NPSSurveys.route_path do
3
+ scope NPSSurveys.route_scope do
4
4
  resources :responses, only: [:index, :create]
5
5
  end
6
6
  end
@@ -1,6 +1,6 @@
1
- class CreateSurveyResponses < ActiveRecord::Migration
1
+ class CreateNpsSurveyResponses < ActiveRecord::Migration
2
2
  def change
3
- create_table :surveys_responses do |t|
3
+ create_table :nps_surveys_responses do |t|
4
4
  t.string :survey, null: false
5
5
  t.integer :user_id, null: false
6
6
  t.integer :score
@@ -1,6 +1,6 @@
1
- module NpsSurveys
1
+ module NPSSurveys
2
2
  class Engine < ::Rails::Engine
3
- isolate_namespace NpsSurveys
3
+ isolate_namespace NPSSurveys
4
4
 
5
5
  initializer :append_migrations do |app|
6
6
  unless app.root.to_s.match root.to_s
@@ -1,3 +1,3 @@
1
- module NpsSurveys
2
- VERSION = '0.0.1'.freeze
1
+ module NPSSurveys
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/nps_surveys.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'foreigner'
2
2
  require 'nps_surveys/engine'
3
3
 
4
- module NpsSurveys
4
+ module NPSSurveys
5
5
  mattr_accessor :controller_parent_class, :route_namespace,
6
6
  :route_path, :route_scope, :current_user
7
7
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- module NpsSurveys
3
+ module NPSSurveys
4
4
  describe ApiInternal::ResponsesController do
5
5
  before(:each) do
6
6
  user = FactoryGirl.create(:user)
7
- NpsSurveys.current_user = lambda do
7
+ NPSSurveys.current_user = lambda do
8
8
  user
9
9
  end
10
10
  end
@@ -16,7 +16,7 @@ module NpsSurveys
16
16
  %w{ hola1 hola2 hola3 }.map do |s|
17
17
  r = Response.new
18
18
  r.survey = s
19
- r.user_id = NpsSurveys.current_user.call.id
19
+ r.user_id = NPSSurveys.current_user.call.id
20
20
  r.save!
21
21
  r
22
22
  end
@@ -0,0 +1,8 @@
1
+ module NpsSurveys
2
+ class Response < ActiveRecord::Base
3
+ self.table_name = 'surveys_responses'
4
+
5
+ validates :survey, presence: true
6
+ validates :user_id, presence: true
7
+ end
8
+ end
@@ -0,0 +1 @@
1
+ NpsSurveys.current_user = lambda { self.current_user }
@@ -1,4 +1,4 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
- mount NpsSurveys::Engine => "/nps"
3
+ mount NPSSurveys::Engine => "/nps"
4
4
  end
@@ -0,0 +1,12 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def up
3
+ create_table :users do |t|
4
+ t.string :name
5
+ t.timestamps
6
+ end
7
+ end
8
+
9
+ def down
10
+ drop_table :users
11
+ end
12
+ end
@@ -11,9 +11,9 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20160721092137) do
14
+ ActiveRecord::Schema.define(:version => 20160728080202) do
15
15
 
16
- create_table "surveys_responses", :force => true do |t|
16
+ create_table "nps_surveys_responses", :force => true do |t|
17
17
  t.string "survey", :null => false
18
18
  t.integer "user_id", :null => false
19
19
  t.integer "score"
@@ -22,6 +22,8 @@ ActiveRecord::Schema.define(:version => 20160721092137) do
22
22
  t.datetime "updated_at", :null => false
23
23
  end
24
24
 
25
+ add_index "nps_surveys_responses", ["user_id"], :name => "nps_surveys_responses_user_id_fk"
26
+
25
27
  create_table "users", :force => true do |t|
26
28
  t.string "login"
27
29
  t.string "password"
@@ -29,4 +31,6 @@ ActiveRecord::Schema.define(:version => 20160721092137) do
29
31
  t.datetime "updated_at", :null => false
30
32
  end
31
33
 
34
+ add_foreign_key "nps_surveys_responses", "users", name: "nps_surveys_responses_user_id_fk"
35
+
32
36
  end
@@ -0,0 +1,184 @@
1
+ Connecting to database specified by database.yml
2
+  (0.2ms) BEGIN
3
+ SQL (0.3ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 07:53:38', 'gandhi_1', 'dragons22', '2016-07-28 07:53:38')
4
+  (7.0ms) COMMIT
5
+  (0.2ms) BEGIN
6
+ SQL (0.2ms) INSERT INTO `surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 07:53:38', NULL, NULL, 'hola1', '2016-07-28 07:53:38', 1)
7
+  (3.2ms) COMMIT
8
+  (0.0ms) BEGIN
9
+ SQL (0.1ms) INSERT INTO `surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 07:53:38', NULL, NULL, 'hola2', '2016-07-28 07:53:38', 1)
10
+  (5.0ms) COMMIT
11
+  (0.0ms) BEGIN
12
+ SQL (0.1ms) INSERT INTO `surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 07:53:38', NULL, NULL, 'hola3', '2016-07-28 07:53:38', 1)
13
+  (2.8ms) COMMIT
14
+  (0.0ms) BEGIN
15
+ SQL (0.1ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 07:53:38', 'gandhi_2', 'dragons22', '2016-07-28 07:53:38')
16
+  (8.0ms) COMMIT
17
+  (0.1ms) BEGIN
18
+ SQL (0.2ms) INSERT INTO `surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 07:53:38', NULL, NULL, 'hola4', '2016-07-28 07:53:38', 2)
19
+  (5.5ms) COMMIT
20
+  (0.1ms) BEGIN
21
+ SQL (0.2ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 07:53:38', 'gandhi_3', 'dragons22', '2016-07-28 07:53:38')
22
+  (4.0ms) COMMIT
23
+ Processing by NPSSurveys::ApiInternal::ResponsesController#index as HTML
24
+ NPSSurveys::Response Load (0.5ms) SELECT `surveys_responses`.* FROM `surveys_responses` WHERE `surveys_responses`.`user_id` = 1
25
+ Completed 200 OK in 5.9ms (Views: 0.1ms | ActiveRecord: 0.5ms)
26
+  (0.1ms) BEGIN
27
+ SQL (0.3ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 07:53:38', 'gandhi_4', 'dragons22', '2016-07-28 07:53:38')
28
+  (4.6ms) COMMIT
29
+ Processing by NPSSurveys::ApiInternal::ResponsesController#create as HTML
30
+ Parameters: {"score"=>"4"}
31
+  (0.1ms) BEGIN
32
+  (0.1ms) ROLLBACK
33
+ Completed 422 Unprocessable Entity in 9.9ms (Views: 0.2ms | ActiveRecord: 0.3ms)
34
+  (0.1ms) BEGIN
35
+ SQL (0.2ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 07:53:38', 'gandhi_5', 'dragons22', '2016-07-28 07:53:38')
36
+  (4.1ms) COMMIT
37
+ Processing by NPSSurveys::ApiInternal::ResponsesController#create as HTML
38
+ Parameters: {"survey"=>"hola", "score"=>"4"}
39
+  (0.1ms) BEGIN
40
+ SQL (0.2ms) INSERT INTO `surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 07:53:38', NULL, NULL, 'hola', '2016-07-28 07:53:38', 5)
41
+  (4.2ms) COMMIT
42
+ Completed 200 OK in 6.4ms (Views: 0.2ms | ActiveRecord: 4.5ms)
43
+ NPSSurveys::Response Load (0.3ms) SELECT `surveys_responses`.* FROM `surveys_responses` ORDER BY `surveys_responses`.`id` DESC LIMIT 1
44
+  (0.1ms) BEGIN
45
+ SQL (0.2ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 07:53:38', 'gandhi_6', 'dragons22', '2016-07-28 07:53:38')
46
+  (4.1ms) COMMIT
47
+ Processing by NPSSurveys::ApiInternal::ResponsesController#create as HTML
48
+ Parameters: {"survey"=>"hola", "score"=>"4"}
49
+  (0.1ms) BEGIN
50
+ SQL (0.2ms) INSERT INTO `surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 07:53:38', NULL, NULL, 'hola', '2016-07-28 07:53:38', 6)
51
+  (4.1ms) COMMIT
52
+ Completed 200 OK in 6.2ms (Views: 0.2ms | ActiveRecord: 4.4ms)
53
+ Connecting to database specified by database.yml
54
+  (0.1ms) BEGIN
55
+ SQL (0.2ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 07:54:49', 'gandhi_1', 'dragons22', '2016-07-28 07:54:49')
56
+  (5.4ms) COMMIT
57
+ Processing by NPSSurveys::ApiInternal::ResponsesController#create as HTML
58
+ Parameters: {"score"=>"4"}
59
+  (0.2ms) BEGIN
60
+  (0.1ms) ROLLBACK
61
+ Completed 422 Unprocessable Entity in 4.1ms (Views: 0.3ms | ActiveRecord: 0.3ms)
62
+  (0.1ms) BEGIN
63
+ SQL (0.2ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 07:54:49', 'gandhi_2', 'dragons22', '2016-07-28 07:54:49')
64
+  (4.5ms) COMMIT
65
+ Processing by NPSSurveys::ApiInternal::ResponsesController#create as HTML
66
+ Parameters: {"survey"=>"hola", "score"=>"4"}
67
+  (0.1ms) BEGIN
68
+ SQL (0.4ms) INSERT INTO `surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 07:54:49', NULL, NULL, 'hola', '2016-07-28 07:54:49', 2)
69
+  (4.0ms) COMMIT
70
+ Completed 200 OK in 7.2ms (Views: 0.2ms | ActiveRecord: 4.5ms)
71
+ NPSSurveys::Response Load (0.2ms) SELECT `surveys_responses`.* FROM `surveys_responses` ORDER BY `surveys_responses`.`id` DESC LIMIT 1
72
+  (0.1ms) BEGIN
73
+ SQL (0.2ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 07:54:49', 'gandhi_3', 'dragons22', '2016-07-28 07:54:49')
74
+  (4.0ms) COMMIT
75
+ Processing by NPSSurveys::ApiInternal::ResponsesController#create as HTML
76
+ Parameters: {"survey"=>"hola", "score"=>"4"}
77
+  (0.1ms) BEGIN
78
+ SQL (0.2ms) INSERT INTO `surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 07:54:49', NULL, NULL, 'hola', '2016-07-28 07:54:49', 3)
79
+  (8.2ms) COMMIT
80
+ Completed 200 OK in 10.5ms (Views: 0.3ms | ActiveRecord: 8.4ms)
81
+  (0.1ms) BEGIN
82
+ SQL (0.1ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 07:54:49', 'gandhi_4', 'dragons22', '2016-07-28 07:54:49')
83
+  (4.0ms) COMMIT
84
+  (0.0ms) BEGIN
85
+ SQL (0.1ms) INSERT INTO `surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 07:54:49', NULL, NULL, 'hola1', '2016-07-28 07:54:49', 4)
86
+  (4.0ms) COMMIT
87
+  (0.0ms) BEGIN
88
+ SQL (0.1ms) INSERT INTO `surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 07:54:49', NULL, NULL, 'hola2', '2016-07-28 07:54:49', 4)
89
+  (4.5ms) COMMIT
90
+  (0.0ms) BEGIN
91
+ SQL (0.1ms) INSERT INTO `surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 07:54:49', NULL, NULL, 'hola3', '2016-07-28 07:54:49', 4)
92
+  (4.1ms) COMMIT
93
+  (0.0ms) BEGIN
94
+ SQL (0.1ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 07:54:49', 'gandhi_5', 'dragons22', '2016-07-28 07:54:49')
95
+  (4.1ms) COMMIT
96
+  (0.0ms) BEGIN
97
+ SQL (0.1ms) INSERT INTO `surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 07:54:49', NULL, NULL, 'hola4', '2016-07-28 07:54:49', 5)
98
+  (4.0ms) COMMIT
99
+  (0.2ms) BEGIN
100
+ SQL (0.3ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 07:54:49', 'gandhi_6', 'dragons22', '2016-07-28 07:54:49')
101
+  (4.1ms) COMMIT
102
+ Processing by NPSSurveys::ApiInternal::ResponsesController#index as HTML
103
+ NPSSurveys::Response Load (0.2ms) SELECT `surveys_responses`.* FROM `surveys_responses` WHERE `surveys_responses`.`user_id` = 4
104
+ Completed 200 OK in 3.8ms (Views: 0.1ms | ActiveRecord: 0.2ms)
105
+ Connecting to database specified by database.yml
106
+ Mysql2::Error: Table 'nps_surveys_test.surveys_responses' doesn't exist: SHOW FULL FIELDS FROM `surveys_responses`
107
+ Mysql2::Error: Table 'nps_surveys_test.surveys_responses' doesn't exist: SHOW FULL FIELDS FROM `surveys_responses`
108
+  (0.1ms) BEGIN
109
+ SQL (0.3ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 11:23:06', 'gandhi_1', 'dragons22', '2016-07-28 11:23:06')
110
+  (6.7ms) COMMIT
111
+ Mysql2::Error: Table 'nps_surveys_test.surveys_responses' doesn't exist: SHOW FULL FIELDS FROM `surveys_responses`
112
+  (0.2ms) BEGIN
113
+ SQL (0.3ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 11:23:06', 'gandhi_2', 'dragons22', '2016-07-28 11:23:06')
114
+  (2.8ms) COMMIT
115
+ Processing by NPSSurveys::ApiInternal::ResponsesController#create as HTML
116
+ Parameters: {"survey"=>"hola", "score"=>"4"}
117
+ Mysql2::Error: Table 'nps_surveys_test.surveys_responses' doesn't exist: SHOW FULL FIELDS FROM `surveys_responses`
118
+ Completed 500 Internal Server Error in 1.0ms
119
+  (0.1ms) BEGIN
120
+ SQL (0.2ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 11:23:06', 'gandhi_3', 'dragons22', '2016-07-28 11:23:06')
121
+  (5.1ms) COMMIT
122
+ Processing by NPSSurveys::ApiInternal::ResponsesController#create as HTML
123
+ Parameters: {"survey"=>"hola", "score"=>"4"}
124
+ Mysql2::Error: Table 'nps_surveys_test.surveys_responses' doesn't exist: SHOW FULL FIELDS FROM `surveys_responses`
125
+ Completed 500 Internal Server Error in 0.9ms
126
+  (0.1ms) BEGIN
127
+ SQL (0.2ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 11:23:06', 'gandhi_4', 'dragons22', '2016-07-28 11:23:06')
128
+  (2.9ms) COMMIT
129
+ Processing by NPSSurveys::ApiInternal::ResponsesController#create as HTML
130
+ Parameters: {"score"=>"4"}
131
+ Mysql2::Error: Table 'nps_surveys_test.surveys_responses' doesn't exist: SHOW FULL FIELDS FROM `surveys_responses`
132
+ Completed 500 Internal Server Error in 1.1ms
133
+ Connecting to database specified by database.yml
134
+  (0.1ms) BEGIN
135
+ SQL (0.3ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 11:23:45', 'gandhi_1', 'dragons22', '2016-07-28 11:23:45')
136
+  (5.5ms) COMMIT
137
+ Processing by NPSSurveys::ApiInternal::ResponsesController#create as HTML
138
+ Parameters: {"score"=>"4"}
139
+  (0.1ms) BEGIN
140
+  (0.1ms) ROLLBACK
141
+ Completed 422 Unprocessable Entity in 4.0ms (Views: 0.8ms | ActiveRecord: 0.2ms)
142
+  (0.1ms) BEGIN
143
+ SQL (0.2ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 11:23:46', 'gandhi_2', 'dragons22', '2016-07-28 11:23:46')
144
+  (4.2ms) COMMIT
145
+ Processing by NPSSurveys::ApiInternal::ResponsesController#create as HTML
146
+ Parameters: {"survey"=>"hola", "score"=>"4"}
147
+  (0.1ms) BEGIN
148
+ SQL (0.2ms) INSERT INTO `nps_surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 11:23:46', NULL, NULL, 'hola', '2016-07-28 11:23:46', 2)
149
+  (4.1ms) COMMIT
150
+ Completed 200 OK in 7.9ms (Views: 0.2ms | ActiveRecord: 4.5ms)
151
+ NPSSurveys::Response Load (0.3ms) SELECT `nps_surveys_responses`.* FROM `nps_surveys_responses` ORDER BY `nps_surveys_responses`.`id` DESC LIMIT 1
152
+  (0.1ms) BEGIN
153
+ SQL (0.2ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 11:23:46', 'gandhi_3', 'dragons22', '2016-07-28 11:23:46')
154
+  (4.2ms) COMMIT
155
+ Processing by NPSSurveys::ApiInternal::ResponsesController#create as HTML
156
+ Parameters: {"survey"=>"hola", "score"=>"4"}
157
+  (0.1ms) BEGIN
158
+ SQL (0.2ms) INSERT INTO `nps_surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 11:23:46', NULL, NULL, 'hola', '2016-07-28 11:23:46', 3)
159
+  (8.2ms) COMMIT
160
+ Completed 200 OK in 11.1ms (Views: 0.3ms | ActiveRecord: 8.5ms)
161
+  (0.1ms) BEGIN
162
+ SQL (0.2ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 11:23:46', 'gandhi_4', 'dragons22', '2016-07-28 11:23:46')
163
+  (4.7ms) COMMIT
164
+  (0.1ms) BEGIN
165
+ SQL (0.2ms) INSERT INTO `nps_surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 11:23:46', NULL, NULL, 'hola1', '2016-07-28 11:23:46', 4)
166
+  (4.1ms) COMMIT
167
+  (0.1ms) BEGIN
168
+ SQL (0.2ms) INSERT INTO `nps_surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 11:23:46', NULL, NULL, 'hola2', '2016-07-28 11:23:46', 4)
169
+  (4.3ms) COMMIT
170
+  (0.1ms) BEGIN
171
+ SQL (0.2ms) INSERT INTO `nps_surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 11:23:46', NULL, NULL, 'hola3', '2016-07-28 11:23:46', 4)
172
+  (4.1ms) COMMIT
173
+  (0.1ms) BEGIN
174
+ SQL (0.2ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 11:23:46', 'gandhi_5', 'dragons22', '2016-07-28 11:23:46')
175
+  (4.0ms) COMMIT
176
+  (0.1ms) BEGIN
177
+ SQL (0.1ms) INSERT INTO `nps_surveys_responses` (`created_at`, `feedback`, `score`, `survey`, `updated_at`, `user_id`) VALUES ('2016-07-28 11:23:46', NULL, NULL, 'hola4', '2016-07-28 11:23:46', 5)
178
+  (4.0ms) COMMIT
179
+  (0.1ms) BEGIN
180
+ SQL (0.2ms) INSERT INTO `users` (`created_at`, `login`, `password`, `updated_at`) VALUES ('2016-07-28 11:23:46', 'gandhi_6', 'dragons22', '2016-07-28 11:23:46')
181
+  (4.4ms) COMMIT
182
+ Processing by NPSSurveys::ApiInternal::ResponsesController#index as HTML
183
+ NPSSurveys::Response Load (0.3ms) SELECT `nps_surveys_responses`.* FROM `nps_surveys_responses` WHERE `nps_surveys_responses`.`user_id` = 4
184
+ Completed 200 OK in 4.0ms (Views: 0.1ms | ActiveRecord: 0.3ms)
@@ -0,0 +1,19 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+ factory :user do
5
+ login { generate(:login) }
6
+ email { generate(:email) }
7
+ first_name 'Andrew'
8
+ last_name 'Wiggin'
9
+ password 'dragons22'
10
+ password_confirmation 'dragons22'
11
+ confirmed_user true
12
+ total_chat_messages 0
13
+ settings(show_welcome: false)
14
+
15
+ trait :with_card do
16
+ association :card
17
+ end
18
+ end
19
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe NpsSurveys::Response do
3
+ describe NPSSurveys::Response do
4
4
  describe 'validations' do
5
5
  subject { described_class.new }
6
6
 
@@ -0,0 +1,4 @@
1
+ class ApplicationController
2
+ def current_user
3
+ end
4
+ end
@@ -0,0 +1,29 @@
1
+ module AuthenticatedTestHelper
2
+ protected
3
+
4
+ def login_as(user, *args)
5
+ user = ensure_user_for_login(user, *args)
6
+ session[:user_id] = user.id
7
+ session[:user_crypted_password] = user.crypted_password
8
+ user
9
+ end
10
+
11
+ def login_as_with_oauth_scope(user, scope, *args)
12
+ user = ensure_user_for_login(user, *args)
13
+ app = ClientApplication.first || FactoryGirl.create(:client_application)
14
+ user.current_token = OauthToken.find_by_user_id(user.id) || Oauth2Token.create!(user: user, client_application: app, scope: scope)
15
+ user.current_token.scope = scope
16
+ user.current_token.save
17
+ user
18
+ end
19
+
20
+ def authorize_as(user)
21
+ @request.env['HTTP_AUTHORIZATION'] = user ? ActionController::HttpAuthentication::Basic.encode_credentials(users(user).login, 'monkey') : nil
22
+ end
23
+
24
+ protected
25
+
26
+ def ensure_user_for_login(user, *args)
27
+ FactoryGirl.create(user, *args)
28
+ end
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nps_surveys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Redbooth team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-21 00:00:00.000000000 Z
11
+ date: 2016-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -28,22 +28,16 @@ dependencies:
28
28
  name: foreigner
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.7'
34
31
  - - ">="
35
32
  - !ruby/object:Gem::Version
36
- version: 1.7.4
33
+ version: '0'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '1.7'
44
38
  - - ">="
45
39
  - !ruby/object:Gem::Version
46
- version: 1.7.4
40
+ version: '0'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: rspec-rails
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -122,12 +116,13 @@ extensions: []
122
116
  extra_rdoc_files: []
123
117
  files:
124
118
  - app/controllers/nps_surveys/api_internal/responses_controller.rb
119
+ - app/exceptions/app_exception/unprocessable_entity.rb~
125
120
  - app/models/nps_surveys/response.rb
126
121
  - app/serializers/nps_surveys/response_presenter.rb
127
122
  - config/initializers/defaults.rb
128
123
  - config/initializers/mount_routes.rb
129
124
  - config/routes.rb
130
- - db/migrate/20160614145840_create_survey_responses.rb
125
+ - db/migrate/20160614145840_create_nps_survey_responses.rb
131
126
  - lib/nps_surveys.rb
132
127
  - lib/nps_surveys/engine.rb
133
128
  - lib/nps_surveys/version.rb
@@ -139,6 +134,7 @@ files:
139
134
  - spec/dummy/app/controllers/application_controller.rb
140
135
  - spec/dummy/app/helpers/application_helper.rb
141
136
  - spec/dummy/app/models/user.rb
137
+ - spec/dummy/app/models/user.rb~
142
138
  - spec/dummy/app/views/layouts/application.html.erb
143
139
  - spec/dummy/config.ru
144
140
  - spec/dummy/config/application.rb
@@ -151,24 +147,29 @@ files:
151
147
  - spec/dummy/config/initializers/backtrace_silencers.rb
152
148
  - spec/dummy/config/initializers/inflections.rb
153
149
  - spec/dummy/config/initializers/mime_types.rb
150
+ - spec/dummy/config/initializers/nps_surveys.rb~
154
151
  - spec/dummy/config/initializers/secret_token.rb
155
152
  - spec/dummy/config/initializers/session_store.rb
156
153
  - spec/dummy/config/initializers/wrap_parameters.rb
157
154
  - spec/dummy/config/locales/en.yml
158
155
  - spec/dummy/config/routes.rb
159
156
  - spec/dummy/db/migrate/20160721092137_create_users.rb
157
+ - spec/dummy/db/migrate/20160721092137_create_users.rb~
160
158
  - spec/dummy/db/schema.rb
161
- - spec/dummy/log/development.log
159
+ - spec/dummy/log/test.log
162
160
  - spec/dummy/public/404.html
163
161
  - spec/dummy/public/422.html
164
162
  - spec/dummy/public/500.html
165
163
  - spec/dummy/public/favicon.ico
166
164
  - spec/dummy/script/rails
167
165
  - spec/factories.rb
166
+ - spec/factories.rb~
168
167
  - spec/models/nps_surveys/response_spec.rb
169
168
  - spec/spec_helper.rb
170
169
  - spec/support/api_json_parser.rb
170
+ - spec/support/application_controller_user.rb~
171
171
  - spec/support/authenticated_test_helper.rb
172
+ - spec/support/authenticated_test_helper.rb~
172
173
  homepage:
173
174
  licenses: []
174
175
  metadata: {}
@@ -188,46 +189,52 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
189
  version: '0'
189
190
  requirements: []
190
191
  rubyforge_project:
191
- rubygems_version: 2.4.5.1
192
+ rubygems_version: 2.4.5
192
193
  signing_key:
193
194
  specification_version: 4
194
195
  summary: Summary of NPS Surveys.
195
196
  test_files:
196
197
  - spec/controllers/nps_surveys/api_internal/responses_controller_spec.rb
197
- - spec/dummy/app/assets/javascripts/application.js
198
- - spec/dummy/app/assets/stylesheets/application.css
198
+ - spec/spec_helper.rb
199
+ - spec/support/authenticated_test_helper.rb
200
+ - spec/support/application_controller_user.rb~
201
+ - spec/support/api_json_parser.rb
202
+ - spec/support/authenticated_test_helper.rb~
203
+ - spec/factories.rb
204
+ - spec/factories.rb~
205
+ - spec/models/nps_surveys/response_spec.rb
199
206
  - spec/dummy/app/controllers/application_controller.rb
207
+ - spec/dummy/app/views/layouts/application.html.erb
200
208
  - spec/dummy/app/helpers/application_helper.rb
209
+ - spec/dummy/app/assets/javascripts/application.js
210
+ - spec/dummy/app/assets/stylesheets/application.css
201
211
  - spec/dummy/app/models/user.rb
202
- - spec/dummy/app/views/layouts/application.html.erb
203
- - spec/dummy/config/application.rb
204
- - spec/dummy/config/boot.rb
212
+ - spec/dummy/app/models/user.rb~
213
+ - spec/dummy/db/migrate/20160721092137_create_users.rb
214
+ - spec/dummy/db/migrate/20160721092137_create_users.rb~
215
+ - spec/dummy/db/schema.rb
216
+ - spec/dummy/log/test.log
217
+ - spec/dummy/Rakefile
218
+ - spec/dummy/public/500.html
219
+ - spec/dummy/public/422.html
220
+ - spec/dummy/public/404.html
221
+ - spec/dummy/public/favicon.ico
222
+ - spec/dummy/script/rails
205
223
  - spec/dummy/config/database.yml
206
- - spec/dummy/config/environment.rb
207
- - spec/dummy/config/environments/development.rb
208
- - spec/dummy/config/environments/production.rb
209
- - spec/dummy/config/environments/test.rb
210
224
  - spec/dummy/config/initializers/backtrace_silencers.rb
211
- - spec/dummy/config/initializers/inflections.rb
212
- - spec/dummy/config/initializers/mime_types.rb
213
- - spec/dummy/config/initializers/secret_token.rb
225
+ - spec/dummy/config/initializers/nps_surveys.rb~
214
226
  - spec/dummy/config/initializers/session_store.rb
215
227
  - spec/dummy/config/initializers/wrap_parameters.rb
228
+ - spec/dummy/config/initializers/mime_types.rb
229
+ - spec/dummy/config/initializers/secret_token.rb
230
+ - spec/dummy/config/initializers/inflections.rb
231
+ - spec/dummy/config/environments/development.rb
232
+ - spec/dummy/config/environments/production.rb
233
+ - spec/dummy/config/environments/test.rb
216
234
  - spec/dummy/config/locales/en.yml
235
+ - spec/dummy/config/application.rb
236
+ - spec/dummy/config/boot.rb
237
+ - spec/dummy/config/environment.rb
217
238
  - spec/dummy/config/routes.rb
218
239
  - spec/dummy/config.ru
219
- - spec/dummy/db/migrate/20160721092137_create_users.rb
220
- - spec/dummy/db/schema.rb
221
- - spec/dummy/log/development.log
222
- - spec/dummy/public/404.html
223
- - spec/dummy/public/422.html
224
- - spec/dummy/public/500.html
225
- - spec/dummy/public/favicon.ico
226
- - spec/dummy/Rakefile
227
240
  - spec/dummy/README.rdoc
228
- - spec/dummy/script/rails
229
- - spec/factories.rb
230
- - spec/models/nps_surveys/response_spec.rb
231
- - spec/spec_helper.rb
232
- - spec/support/api_json_parser.rb
233
- - spec/support/authenticated_test_helper.rb
@@ -1,12 +0,0 @@
1
- Connecting to database specified by database.yml
2
- Connecting to database specified by database.yml
3
-  (0.3ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` 
4
-  (41.8ms) DROP DATABASE IF EXISTS `nps_surveys_test`
5
-  (0.2ms) CREATE DATABASE `nps_surveys_test` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`
6
-  (29.2ms) CREATE TABLE `surveys_responses` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `survey` varchar(255) NOT NULL, `user_id` int(11) NOT NULL, `score` int(11), `feedback` text, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB
7
-  (27.7ms) CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `login` varchar(255), `password` varchar(255), `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB
8
-  (25.8ms) CREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=InnoDB
9
-  (52.3ms) CREATE UNIQUE INDEX `unique_schema_migrations` ON `schema_migrations` (`version`)
10
-  (0.2ms) SELECT version FROM `schema_migrations`
11
-  (5.0ms) INSERT INTO `schema_migrations` (version) VALUES ('20160721092137')
12
-  (4.6ms) INSERT INTO `schema_migrations` (version) VALUES ('20160614145840')