dbAccessor 0.0.7 → 0.0.9

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: 7779c4a2bb87572cd744bc3fb1f6a7ec72104936
4
- data.tar.gz: ead38bab42b71e9df42c7539c57024ba298673ad
3
+ metadata.gz: 58367dd06a27c55b261a30538dd03f22cd72807c
4
+ data.tar.gz: 40f09b2fa40c4f702e3550ba07576d35651a8d98
5
5
  SHA512:
6
- metadata.gz: 7d9f4826add8a051d3258e64817b88a84153184982c1b091fddd542c1cb07a20cb3fa84713b4d78fb25d32583347387fff02007d20b6105ab4b107bd759e18f9
7
- data.tar.gz: 740af56e79f80c311ca395cfb0bb8b46766bba327003dbd22f7edacf3bfbc3e04c2b4fe3270988cfc86dc3ac4706555890fc6d0364f58a1698a6d2bf694f5ed3
6
+ metadata.gz: b0ccffa53348b755048ce4bc920a5c534f02c24375f979a0de7213afd960cc9e67775293eb379bb02fb78d78646ca08d66b85811a7e7653f41137ec3db2ade33
7
+ data.tar.gz: 75985ecee25e69f0f3fdc32352157430b4e572516893cbe5d3a8175e0d477553f35975b0e83ebdb4af6792af4fe571da4577c649e1522119b8164bd1f3269820
data/dbAccessor.gemspec CHANGED
@@ -31,4 +31,6 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "activerecord", "~> 4.1", ">= 4.1.1"
32
32
  spec.add_development_dependency "rake", "~> 10.3", ">= 10.3.2"
33
33
  spec.add_development_dependency "pg", "~> 0.17", ">= 0.17.1"
34
+ spec.add_development_dependency "auth_manager"
35
+ spec.add_development_dependency "redis"
34
36
  end
@@ -21,12 +21,16 @@ class DbAccessor::Updater < Db_Accessor::Base
21
21
  waited_keys = [:model_name,:attributes]
22
22
  if validate(given_param,waited_keys) && valid_object_columns?(given_param[:model_name],given_param[:attributes]) && valid_attributes_values?(given_param[:attributes])
23
23
 
24
-
25
24
  model_name=Object.const_get(given_param[:model_name])
26
- model_name.update_all(given_param[:attributes]) if condition.empty?
27
- model_name.update_all(given_param[:attributes],condition) if condition.is_a?(String) && !condition.empty?
28
-
29
- return_response(200,"Successfully updated")
25
+ list = model_name.all if condition.empty?
26
+ list = model_name.where(condition) if condition.is_a?(Hash) && !condition.empty?
27
+ result = false
28
+ list.each do |o|
29
+ hash = {model_name: model_name.to_s,attributes:{ o.id => given_param[:attributes]}}
30
+ result = update_by_id(hash)
31
+ break if !result
32
+ end
33
+ result ? return_response(200,"Successfully updated") : return_response(400,"Not updated")
30
34
  else
31
35
  return_response(400,"Not updated")
32
36
  end
@@ -1,3 +1,3 @@
1
1
  module DbAccessor
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.9"
3
3
  end
data/spec/deleter_spec.rb CHANGED
@@ -3,7 +3,7 @@ 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: 5}}
6
+ given_param = { model_name: "User",condition: {id: 3}}
7
7
  context "when the object is deleted" do
8
8
  it {expect((DbAccessor::Deleter.delete_all(given_param))[:code]).to eq 200 }
9
9
 
@@ -79,7 +79,7 @@ describe DbAccessor::Deleter do
79
79
  context "when parameter's keys are invalid" do
80
80
  given_param={model_name: "User", i: [1,2] }
81
81
  it {expect((DbAccessor::Deleter.delete_by_id(given_param))[:code]).to eq 400 }
82
- given_param = {model: "Application",id: [5]}
82
+ given_param = {model: "Application",id: [3]}
83
83
  it {expect((DbAccessor::Deleter.delete_by_id(given_param))[:code]).to eq 400 }
84
84
  end
85
85
 
@@ -3,8 +3,38 @@ require 'active_record'
3
3
  require_relative 'user'
4
4
 
5
5
  class Application < ActiveRecord::Base
6
-
6
+ attr_accessor :api_key_to_update
7
+
7
8
  validates_presence_of :name, :api_key, :url
8
9
  validates_uniqueness_of :api_key, :url
9
10
  belongs_to :user
11
+
12
+
13
+ after_save :save_app
14
+ before_update :save_status
15
+ after_update :update_app
16
+
17
+ private
18
+
19
+ def save_status
20
+ @api_key_to_update = api_key
21
+ end
22
+
23
+ def save_app
24
+ option = {user: false,app: true}
25
+ to_save = {api_key: api_key}.to_json
26
+ AuthManager::Adder.save?(to_save,option)
27
+ end
28
+
29
+ def update_app
30
+ option = {user: false,app: true}
31
+ old_obj = {api_key: @api_key_to_update}.to_json
32
+ to_update = {api_key: api_key}.to_json
33
+ if deleted == false
34
+ AuthManager::Updater.update(old_obj,to_update,option)
35
+ else
36
+ AuthManager::Deleter.delete?(to_update,option)
37
+ end
38
+ end
39
+
10
40
  end
@@ -1,9 +1,43 @@
1
1
  require 'active_record'
2
+ require 'auth_manager'
3
+ require 'json'
2
4
  require_relative 'application'
3
5
 
4
6
  class User < ActiveRecord::Base
5
-
7
+
8
+ attr_accessor :login_to_update, :passwd_to_update
9
+
6
10
  validates_presence_of :login, :password, :email
7
11
  validates_uniqueness_of :login, :email
8
- has_many :applications
12
+ has_many :applications, dependent: :destroy
13
+
14
+ after_save :save_user
15
+ before_update :save_status
16
+ after_update :update_user
17
+
18
+ private
19
+
20
+ def save_status
21
+ @login_to_update = login
22
+ @passwd_to_update = password
23
+ end
24
+
25
+ def save_user
26
+ option = {user: true,app: false}
27
+ to_save = {login: login,password: password}.to_json
28
+ AuthManager::Adder.save?(to_save,option)
29
+ end
30
+
31
+ def update_user
32
+ option = {user: true,app: false}
33
+ old_obj = {login: @login_to_update,password: @passwd_to_update}.to_json
34
+ to_update = {login: login,password: password}.to_json
35
+ if deleted == false
36
+ AuthManager::Updater.update(old_obj,to_update,option)
37
+ else
38
+ AuthManager::Deleter.delete?(to_update,option)
39
+ end
40
+ end
41
+
42
+
9
43
  end
@@ -1,4 +1,5 @@
1
1
  require 'active_record'
2
+ require 'auth_manager'
2
3
  require_relative 'item'
3
4
  require_relative 'action'
4
5
 
data/spec/reader_spec.rb CHANGED
@@ -27,7 +27,7 @@ describe DbAccessor::Reader do
27
27
  describe ".condition_select" do
28
28
 
29
29
  context "when it reads one or many items on table with a condition" do
30
- it {expect((DbAccessor::Reader.condition_select({model_name: "User" , condition: {login: "fabira3"}}))[:code]).to eq 200 }
30
+ it {expect((DbAccessor::Reader.condition_select({model_name: "User" , condition: {login: "modou"}}))[:code]).to eq 200 }
31
31
  end
32
32
 
33
33
  context "when the condition is not satisfied" do
@@ -52,7 +52,7 @@ describe DbAccessor::Reader do
52
52
  describe ".select_by_id" do
53
53
 
54
54
  context "when it reads on a model with an id" do
55
- it {expect((DbAccessor::Reader.select_by_id({model_name: "User",identifiers: [7,8,9]}))[:code]).to eq 200 }
55
+ it {expect((DbAccessor::Reader.select_by_id({model_name: "User",identifiers: [5]}))[:code]).to eq 200 }
56
56
  end
57
57
 
58
58
  context "when one of the ids is incorrect" do
data/spec/updater_spec.rb CHANGED
@@ -4,7 +4,7 @@ describe DbAccessor::Updater do
4
4
 
5
5
  describe ".update_by_id" do
6
6
  context "updates one or many users by id" do
7
- param = {model_name: "User",attributes: { 3 => {login: "fabira"}} }
7
+ param = {model_name: "User",attributes: { 72 => {login: "mamadouPouye"}} }
8
8
  it {expect((DbAccessor::Updater.update_by_id(param))[:code]).to eq 200 }
9
9
  end
10
10
 
@@ -63,13 +63,13 @@ describe DbAccessor::Updater do
63
63
  end
64
64
 
65
65
  describe ".update_all_objects" do
66
- parameter={model_name: "User", attributes: {login: 'fabira3',password: 'passe'}}
66
+ parameter={model_name: "User", attributes: {login: 'doudouna',password: 'passe'}}
67
67
  context "when it updates all model objects" do
68
68
  it {expect((DbAccessor::Updater.update_all_objects(parameter))[:code]).to eq 200 }
69
69
  end
70
70
 
71
71
  context "when all model objects that satisfy the condition are updated" do
72
- condition="id == 3"
72
+ condition={login: 'modou'}
73
73
  it {expect((DbAccessor::Updater.update_all_objects(parameter,condition))[:code]).to eq 200 }
74
74
  end
75
75
 
data/spec/writer_spec.rb CHANGED
@@ -6,9 +6,9 @@ describe DbAccessor::Writer do
6
6
  nb = rand(1000)
7
7
  api_key = UUID.new.generate
8
8
 
9
- let(:user) { {model_name: 'User',content: {login: 'ab'+nb.to_s,password: 'passer',firstname: 'Ndeye Fatou', lastname: 'Dieng',email: 'ab'+nb.to_s+'@gmail.com',gender: 'M'}} }
9
+ let(:user) { {model_name: 'User',content: {login: 'modou'+nb.to_s,password: 'passeraa',firstname: 'Ndeye Fatou', lastname: 'Dieng',email: 'ab'+nb.to_s+'@gmail.com',gender: 'M'}} }
10
10
 
11
- let(:app) { {model_name: 'Application',content: {name: 'Wiki'+nb.to_s,api_key: api_key,url: 'http://www.wiki'+nb.to_s+'.com',user_id: 2}} }
11
+ let(:app) { {model_name: 'Application',content: {name: 'Wikina'+nb.to_s,api_key: api_key,url: 'http://www.wiki'+nb.to_s+'.com',user_id: 2}} }
12
12
 
13
13
 
14
14
  describe".write_object" do
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.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - fabira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-26 00:00:00.000000000 Z
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -198,6 +198,34 @@ dependencies:
198
198
  - - ">="
199
199
  - !ruby/object:Gem::Version
200
200
  version: 0.17.1
201
+ - !ruby/object:Gem::Dependency
202
+ name: auth_manager
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ type: :development
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ - !ruby/object:Gem::Dependency
216
+ name: redis
217
+ requirement: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ type: :development
223
+ prerelease: false
224
+ version_requirements: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - ">="
227
+ - !ruby/object:Gem::Version
228
+ version: '0'
201
229
  description: '"Module d''acces a la base de donnees "'
202
230
  email:
203
231
  - fabira90@gmail.com