dbAccessor 0.1.6 → 0.1.7

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: 81b5c788930e7f1eb49c7dabf748020bb49551b1
4
- data.tar.gz: 28707829eb2eeda2982a270f082966972df3701c
3
+ metadata.gz: 701e6d4e9ab5ce11aae92b954dc447a8201ab0b4
4
+ data.tar.gz: ca327af2f7c65250a2f5ab25c1a18178ce3b05fd
5
5
  SHA512:
6
- metadata.gz: b945c8d58e369547feea8724af0c273058999ddfaeda20c602df4437e8a2203ae88c6a9059ca644f6b161923f9ee7e792f1de71b0950b7361b8581850db8e39f
7
- data.tar.gz: 3d35f1926f11995b97c655d52593187ce60aa2cefccc9cbcbf7dab053aa05e2ba39eee167eba938ec1192c7522b7adc00a21c637210c9cea76e60c3d3d9b000d
6
+ metadata.gz: bdb5d7952f1c4f661b4ccf626b6662d9e8a008cc8217d696c9d73bce406c61912446194861e74fc69d85134d0928c3b6e85e0b40e76dca2d52e1c739c8c1b744
7
+ data.tar.gz: f61092eba402b8ac33e5120b461e6a4f51ffabec79c5c40af2a0fd3daa9ee244e754e99312a3c5b1828d3e92e3b3c7ff3584b17b69c726cc56da078327a564b1
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --format nested
1
+ --format d
2
2
  --color
data/Gemfile CHANGED
@@ -1,5 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
  gem "autotest"
3
+ gem 'rspec-autotest'
3
4
  gem "autotest-fsevent"
4
5
  gem "autotest-growl"
5
6
  gem "ZenTest"
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.required_ruby_version = ">= 1.9"
24
24
  spec.add_development_dependency "bundler", "~> 1.5"
25
25
  spec.add_development_dependency "uuid", "~> 2.3", ">= 2.3.7"
26
- spec.add_development_dependency "rspec", "~> 2.6"
26
+ spec.add_development_dependency "rspec"
27
27
  spec.add_development_dependency "activerecord", "~> 4.1", ">= 4.1.1"
28
28
  spec.add_development_dependency "rake", "~> 10.3", ">= 10.3.2"
29
29
  spec.add_development_dependency "pg", "~> 0.17", ">= 0.17.1"
@@ -62,7 +62,7 @@ module Db_Accessor
62
62
  engine_columns = [:id,:name,:engine_conf,:application_id]
63
63
  engine_data_columns = [:id,:customer_id,:item_id,:preference,:engine_id]
64
64
  app_columns = [:id,:name,:api_key,:url,:user_id]
65
- user_columns = [:id,:login,:password,:firstname,:lastname,:gender,:email]
65
+ user_columns = [:id,:login,:password,:firstname,:lastname,:gender,:email, :admin]
66
66
 
67
67
  keys = content.keys
68
68
  if model_name == "User"
@@ -17,40 +17,10 @@ class DbAccessor::Deleter < Db_Accessor::Base
17
17
  end
18
18
  end
19
19
 
20
-
21
- def self.delete_by_id(given_param)
22
- waited_keys = [:model_name,:id]
23
- if validate(given_param,waited_keys) && validate_id(given_param[:id])
24
- model_name = get_model_name(given_param)
25
- objects = model_name.find(given_param[:id])
26
- objects.each do |o|
27
- o.deleted=true
28
- o.save
29
- end
30
- return_response(200,"success")
31
- else
32
- return_response(400,"Not deleted")
33
- end
34
- end
35
-
36
20
  def self.validate(param,waited_keys)
37
21
  param.is_a?(Hash) && valid_keys?(param,waited_keys) && !validate_argument(param) && is_model?(param[:model_name])
38
22
  end
39
23
 
40
- def self.validate_id(param)
41
- if param.is_a?(Array)
42
- param.each do |v|
43
- if !(v.is_a?(Fixnum))
44
- return false
45
- break
46
- end
47
- end
48
- else
49
- return false
50
- end
51
- return true
52
- end
53
-
54
24
  def self.valid_condition?(param)
55
25
  condition = param[:condition]
56
26
  model_name = param[:model_name]
@@ -7,7 +7,7 @@ class DbAccessor::Updater < Db_Accessor::Base
7
7
  def self.update_by_id(given_object)
8
8
  waited_keys = [:model_name,:attributes]
9
9
  if validate(given_object,waited_keys) && valid_attributes_pattern?(given_object[:model_name],given_object[:attributes])
10
- get_model_name(given_object).update(get_attributes(given_object).keys,get_attributes(given_object).values)
10
+ var = get_model_name(given_object).update(get_attributes(given_object).keys,get_attributes(given_object).values)
11
11
  return_response(200,"Succesfully updated")
12
12
  else
13
13
  return_response(400,"Not updated")
@@ -1,3 +1,3 @@
1
1
  module DbAccessor
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -3,11 +3,25 @@ require_relative 'spec_helper'
3
3
  describe DbAccessor::Deleter do
4
4
 
5
5
  describe ".delete_all" do
6
- given_param = { model_name: "User",condition: {id: 3}}
6
+ nb = rand(1000)
7
+ api_key = UUID.new.generate
8
+ let(:app) { {model_name: 'Application',content: {name: 'desert'+nb.to_s,api_key: api_key,url: 'http://www.desert'+nb.to_s+'.com',user_id: 2}} }
9
+ let(:user) { {model_name: 'User',content: {login: 'diakhoumpa'+nb.to_s,password: 'passeraa',firstname: 'Ndeye Fatou', lastname: 'Dieng',email: 'diakhouumpa'+nb.to_s+'@gmail.com',gender: 'M'}} }
7
10
  context "when the object is deleted" do
8
- it {expect((DbAccessor::Deleter.delete_all(given_param))[:code]).to eq 200 }
9
-
10
- it {expect((DbAccessor::Deleter.delete_all({model_name: "Application",condition: {name: 'Wikia'}}))[:code]).to eq 200 }
11
+ before(:each) do
12
+ DbAccessor::Writer.write_object(app)
13
+ DbAccessor::Writer.write_object(user)
14
+ end
15
+ it do
16
+ found_id = DbAccessor::Reader.simple_select( { model_name: 'User', action_on: 'first' } )[:message].id
17
+ given_param = { model_name: "User", condition: { id: found_id }}
18
+ expect((DbAccessor::Deleter.delete_all(given_param))[:code]).to eq 200
19
+ end
20
+
21
+ it do
22
+ found_id = DbAccessor::Reader.simple_select( { model_name: 'Application', action_on: 'first' } )[:message].id
23
+ expect((DbAccessor::Deleter.delete_all({model_name: "Application",condition: { id: found_id }}))[:code]).to eq 200
24
+ end
11
25
 
12
26
  it {expect((DbAccessor::Deleter.delete_all({model_name: "User",condition: {login: 'fabira',password: 'passera'}}))[:code]).to eq 200 }
13
27
  end
@@ -50,41 +64,4 @@ describe DbAccessor::Deleter do
50
64
  end
51
65
 
52
66
  end
53
-
54
- describe ".delete_by_id" do
55
- context "when the object find by id is deleted" do
56
- given_param={model_name: "Application", id: [4]}
57
- it {expect((DbAccessor::Deleter.delete_by_id(given_param))[:code]).to eq 200 }
58
-
59
- given_param={model_name: "User", id: [4]}
60
- it {expect((DbAccessor::Deleter.delete_by_id(given_param))[:code]).to eq 200 }
61
- end
62
-
63
- context "when the id's format is invalid" do
64
- given_param={model_name: "User", id: "coucou"}
65
- it {expect((DbAccessor::Deleter.delete_by_id(given_param))[:code]).to eq 400 }
66
- end
67
-
68
-
69
- context "when one or many parameters are empty or nil" do
70
- given_param={model_name: "User", id: nil}
71
- it {expect((DbAccessor::Deleter.delete_by_id(given_param))[:code]).to eq 400 }
72
- end
73
-
74
- context "when the model name is invalid" do
75
- given_param={model_name: "U3466", id: [1,2,3]}
76
- it {expect((DbAccessor::Deleter.delete_by_id(given_param))[:code]).to eq 400 }
77
- end
78
-
79
- context "when parameter's keys are invalid" do
80
- given_param={model_name: "User", i: [1,2] }
81
- it {expect((DbAccessor::Deleter.delete_by_id(given_param))[:code]).to eq 400 }
82
- given_param = {model: "Application",id: [3]}
83
- it {expect((DbAccessor::Deleter.delete_by_id(given_param))[:code]).to eq 400 }
84
- end
85
-
86
- context "when the parameter is nil" do
87
- it {expect((DbAccessor::Deleter.delete_by_id(nil))[:code]).to eq 400 }
88
- end
89
- end
90
67
  end
@@ -13,7 +13,5 @@ class CreateActions < ActiveRecord::Migration
13
13
  end
14
14
  end
15
15
 
16
- CreateActions.down
17
-
18
-
19
-
16
+ CreateActions.down if ActiveRecord::Base.connection.table_exists? 'actions'
17
+ CreateActions.up
@@ -10,12 +10,12 @@ class CreateApplications < ActiveRecord::Migration
10
10
  a.timestamps
11
11
  end
12
12
  add_index :applications, :user_id
13
- end
14
-
13
+ end
14
+
15
15
  def self.down
16
16
  drop_table :applications
17
17
  end
18
18
  end
19
19
 
20
+ CreateApplications.down if ActiveRecord::Base.connection.table_exists? 'applications'
20
21
  CreateApplications.up
21
-
@@ -16,4 +16,4 @@ class CreateAssignments < ActiveRecord::Migration
16
16
  end
17
17
  end
18
18
 
19
- CreateAssignments.down
19
+ CreateAssignments.down if ActiveRecord::Base.connection.table_exists? 'assignments'
@@ -15,5 +15,5 @@ class CreateEngineData < ActiveRecord::Migration
15
15
  end
16
16
 
17
17
  end
18
- CreateEngineData.down
18
+ CreateEngineData.down if ActiveRecord::Base.connection.table_exists? 'engine_data'
19
19
  CreateEngineData.up
@@ -4,6 +4,7 @@ class CreateEngines < ActiveRecord::Migration
4
4
  e.string :name
5
5
  e.column :engine_conf, :json
6
6
  e.integer :application_id
7
+ e.boolean :deleted, :default => false
7
8
  e.timestamps
8
9
  end
9
10
  add_index :engines, :application_id
@@ -15,5 +16,5 @@ class CreateEngines < ActiveRecord::Migration
15
16
 
16
17
  end
17
18
 
18
- CreateEngines.down
19
+ CreateEngines.down if ActiveRecord::Base.connection.table_exists? 'engines'
19
20
  CreateEngines.up
@@ -9,14 +9,16 @@ class CreateUsers < ActiveRecord::Migration
9
9
  u.string :lastname
10
10
  u.string :gender
11
11
  u.string :email
12
+ u.boolean :admin, default: false
12
13
  u.boolean :deleted, :default => false
13
14
  u.timestamps
14
15
  end
15
- end
16
-
16
+ end
17
+
17
18
  def self.down
18
19
  drop_table :users
19
20
  end
20
21
  end
21
22
 
23
+ CreateUsers.down if ActiveRecord::Base.connection.table_exists? 'users'
22
24
  CreateUsers.up
@@ -5,5 +5,3 @@ require_relative '../dbTest/migration/create_table_engines'
5
5
  require_relative '../dbTest/migration/create_table_engine_data'
6
6
  require_relative '../dbTest/migration/create_table_actions'
7
7
  require_relative '../dbTest/migration/create_table_assignments'
8
-
9
-
@@ -2,6 +2,16 @@ require_relative 'spec_helper'
2
2
 
3
3
 
4
4
  describe DbAccessor::Reader do
5
+ nb = rand(50)
6
+
7
+ api_key = UUID.new.generate
8
+ let(:app) { {model_name: 'Application',content: {name: 'desert'+nb.to_s,api_key: api_key,url: 'http://www.desert'+nb.to_s+'.com',user_id: 1}} }
9
+ let(:user) { {model_name: 'User',content: {login: 'diakhoumpa'+nb.to_s,password: 'passeraa',firstname: 'Ndeye Fatou', lastname: 'Dieng',email: 'diakhouumpa'+nb.to_s+'@gmail.com',gender: 'M'}} }
10
+
11
+ before :each do
12
+ DbAccessor::Writer.write_object(app)
13
+ DbAccessor::Writer.write_object(user)
14
+ end
5
15
 
6
16
  describe ".simple_select" do
7
17
  context "when all model's items are found" do
@@ -28,7 +38,10 @@ describe DbAccessor::Reader do
28
38
  describe ".condition_select" do
29
39
 
30
40
  context "when it reads one or many items on table with a condition" do
31
- it {expect((DbAccessor::Reader.condition_select({model_name: "User" , condition: {login: "modou"}}))[:code]).to eq 200 }
41
+ it do
42
+ found_login = DbAccessor::Reader.simple_select( { model_name: 'User', action_on: 'first' } )[:message].login
43
+ expect((DbAccessor::Reader.condition_select({model_name: "User" , condition: { login: found_login }}))[:code]).to eq 200
44
+ end
32
45
  end
33
46
 
34
47
  context "when the condition is not satisfied" do
@@ -71,7 +84,7 @@ describe DbAccessor::Reader do
71
84
  describe ".linked_models_select" do
72
85
 
73
86
  context "when it reads models on model with a condition" do
74
- it {expect((DbAccessor::Reader.linked_models_select({model_name: "User", condition: { id: 2}, models: "applications"}))[:code]).to eq 200 }
87
+ it {expect((DbAccessor::Reader.linked_models_select({model_name: "User", condition: { id: 1}, models: "applications"}))[:code]).to eq 200 }
75
88
  end
76
89
 
77
90
  context "when a parameter is empty or empty" do
@@ -9,15 +9,22 @@ describe DbAccessor::Updater do
9
9
  describe ".update_by_id" do
10
10
 
11
11
  context "updates one or many users by id" do
12
- param = {model_name: "User",attributes: { 149 => {login: "mamadouPouye"}} }
12
+ DbAccessor::Writer.write_object({model_name: 'User',content: {login: 'diakhoumpa'+nb.to_s,password: 'passeraa',firstname: 'Ndeye Fatou', lastname: 'Dieng',email: 'diakhouumpa'+nb.to_s+'@gmail.com',gender: 'M'}})
13
+ found_id = DbAccessor::Reader.simple_select( { model_name: 'User', action_on: 'first' } )[:message].id
14
+ param = {model_name: "User",attributes: { found_id => {login: "mamadouPouye"}} }
13
15
  it {expect((DbAccessor::Updater.update_by_id(param))[:code]).to eq 200 }
14
16
  end
15
17
 
16
18
  context "updates one or many applications by id" do
17
- param = {model_name: "Application",attributes: {15 => {api_key: UUID.new.generate}} }
19
+ api_key = UUID.new.generate
20
+ DbAccessor::Writer.write_object({model_name: 'Application',content: {name: 'desert'+nb.to_s,api_key: api_key,url: 'http://www.desert'+nb.to_s+'.com',user_id: 1}})
21
+ found_id = DbAccessor::Reader.simple_select( { model_name: 'Application', action_on: 'first' } )[:message].id
22
+ param = {model_name: "Application",attributes: {found_id => {api_key: UUID.new.generate}} }
18
23
  it {expect((DbAccessor::Updater.update_by_id(param))[:code]).to eq 200 }
19
24
 
20
- param = {model_name: "Engine",attributes: {1 => {engine_conf: {similarity_metric: 'similarity_metric',reco_algo: 'reco_algo',neighborhood: 'neighborhood'}.to_json} } }
25
+ DbAccessor::Writer.write_object({model_name: 'Engine',content: {name: 'engine'+nb.to_s,engine_conf: {action: ['LIKE','SHARE'],score: [2,5],algorithm: 'Person',type: 'UserBased', neighborhood: 5 }.to_json ,application_id: 1}})
26
+ found_id = DbAccessor::Reader.simple_select( { model_name: 'Engine', action_on: 'first' } )[:message].id
27
+ param = {model_name: "Engine",attributes: { found_id => {engine_conf: {similarity_metric: 'similarity_metric',reco_algo: 'reco_algo',neighborhood: 'neighborhood'}.to_json} } }
21
28
  it {expect((DbAccessor::Updater.update_by_id(param))[:code]).to eq 200 }
22
29
  end
23
30
 
@@ -80,8 +87,13 @@ describe DbAccessor::Updater do
80
87
  end
81
88
 
82
89
  context "when all model objects that satisfy the condition are updated" do
83
- condition={login: 'modou'}
84
- it {expect((DbAccessor::Updater.update_all_objects(parameter,condition))[:code]).to eq 200 }
90
+ it do
91
+ Redis.current.del('users')
92
+ parameter={model_name: "User", attributes: {password: "password#{nb}"}}
93
+ found_login = DbAccessor::Reader.simple_select( { model_name: 'User', action_on: 'last' } )[:message].login
94
+ condition = { login: found_login }
95
+ expect((DbAccessor::Updater.update_all_objects(parameter,condition))[:code]).to eq 200
96
+ end
85
97
  end
86
98
 
87
99
  context "when model's attributes are not correct" do
@@ -10,14 +10,22 @@ describe DbAccessor::Writer do
10
10
 
11
11
  let(:app) { {model_name: 'Application',content: {name: 'desert'+nb.to_s,api_key: api_key,url: 'http://www.desert'+nb.to_s+'.com',user_id: 2}} }
12
12
 
13
- let(:engine) { {model_name: 'Engine',content: {name: 'engine'+nb.to_s,engine_conf: {action: ['LIKE','SHARE'],score: [2,5],algorithm: 'Person',type: 'UserBased', neighborhood: 5 }.to_json ,application_id: 2}} }
14
-
15
- describe".write_object" do
13
+ let(:engine) { {model_name: 'Engine',content: {name: 'engine'+nb.to_s,engine_conf: {action: ['LIKE','SHARE'],score: [2,5],algorithm: 'Person',type: 'UserBased', neighborhood: 5 }.to_json ,application_id: 1}} }
16
14
 
17
15
  context "when a user is saved in database" do
18
16
  it {expect((DbAccessor::Writer.write_object(user))[:code]).to eq 201}
19
17
  end
20
18
 
19
+ context "when an admin user is saved in database" do
20
+ it do
21
+ admin_user = user
22
+ admin_user[:content][:login] = "admin#{nb.to_s}"
23
+ admin_user[:content][:email] = "admin#{nb.to_s}@gmail.com"
24
+ admin_user[:content][:admin] = true
25
+ expect((DbAccessor::Writer.write_object(admin_user))[:code]).to eq 201
26
+ end
27
+ end
28
+
21
29
  context "when an application is saved in database" do
22
30
  it {expect((DbAccessor::Writer.write_object(app))[:code]).to eq 201}
23
31
  end
@@ -73,5 +81,3 @@ describe DbAccessor::Writer do
73
81
  end
74
82
 
75
83
  end
76
-
77
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbAccessor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - fabira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-08 00:00:00.000000000 Z
11
+ date: 2014-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -48,16 +48,16 @@ dependencies:
48
48
  name: rspec
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '2.6'
53
+ version: '0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - "~>"
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: '2.6'
60
+ version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: activerecord
63
63
  requirement: !ruby/object:Gem::Requirement