myfinance-rails 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4eb3008e8ac8821247621f307d62693fc4f0e0e6
4
- data.tar.gz: 7abfe8346b03fceb1f227c59ae2d6068d16eff24
3
+ metadata.gz: 456f4ce9dd6880ae41a26f481ce0a052020e6711
4
+ data.tar.gz: 24c8da38786e3bffd15019e3f94a765f251e6635
5
5
  SHA512:
6
- metadata.gz: bd997e73fb908c670f4a28b16de5b602a99e9537210f774dcf89ac4eadbbaabf5770563b49be545bf417e2f75f5a120bc8d17e294421fcdd083f36b6194b0d6a
7
- data.tar.gz: 0be7c55379a0c1d96e2be00d563f024c03afe575524a33ea8acabcacfdf0d058708da4db91cca92bdb0dfc93dde4ffa6e234ed0343e286bc9f92e6ddde4a67f3
6
+ metadata.gz: a86f379ebdc9a02b97c21d44068a73047c038d379bce3b4038089dbb0c70fbdc51ce0993784d2bcd2adc5484e897a8d4d8911ad467ad48de44a16a9f8af1729f
7
+ data.tar.gz: baab5c1fd42a3ae97d2e2d843884dfc61defebc3ee2cde9145f6a85dc68628661a0164ccc0d60ad7f5e9b7d7ce3b4a9b4c6ca8b3cdad72bbda19031ced623a54
@@ -2,8 +2,7 @@ module Myfinance
2
2
 
3
3
  def self.categoria_id(nome)
4
4
  mid = nil
5
- response = lget '/categories.json'
6
- response.each do | item |
5
+ categorias.each do | item |
7
6
  category = item['category']
8
7
  if category['full_name'] == nome
9
8
  mid = category['id']
@@ -13,5 +12,8 @@ module Myfinance
13
12
  mid
14
13
  end
15
14
 
15
+ def self.categorias
16
+ lget '/categories.json'
17
+ end
16
18
  end
17
19
 
@@ -10,18 +10,39 @@ module Myfinance
10
10
 
11
11
  def self.centro_id(nome, custo = nil)
12
12
  mid = nil
13
- response = lget '/classification_centers.json'
14
- response.each do | item |
13
+ centros(custo).each do | item |
15
14
  cc = item['classification_center']
16
15
  if cc['name'] == nome
17
- if custo.nil? or cc['cost_center'] == custo
18
- mid = cc['id']
19
- end
16
+ mid = cc['id']
20
17
  break
21
18
  end
22
19
  end
23
20
  mid
24
21
  end
25
22
 
23
+ def self.centros(custo = nil)
24
+ items = Array.new
25
+ classification_centers.each do | item |
26
+ cc = item['classification_center']
27
+ if custo.nil?
28
+ items.push(item)
29
+ else
30
+ if custo
31
+ if cc['cost_center']
32
+ items.push(item)
33
+ end
34
+ else
35
+ if cc['revenue_center']
36
+ items.push(item)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ items
42
+ end
43
+
44
+ def self.classification_centers
45
+ lget '/classification_centers.json'
46
+ end
26
47
  end
27
48
 
@@ -13,6 +13,10 @@ module Myfinance
13
13
  response
14
14
  end
15
15
 
16
+ def self.conta_a_receber(id, entity_id)
17
+ lget "/entities/#{entity_id}/receivable_accounts/#{id}.json"
18
+ end
19
+
16
20
 
17
21
  end
18
22
 
@@ -2,8 +2,7 @@ module Myfinance
2
2
 
3
3
  def self.entidade_id(nome)
4
4
  mid = nil
5
- response = lget '/entities.json'
6
- response.each do | ent |
5
+ entidades.each do | ent |
7
6
  cliente = ent['entity']
8
7
  if cliente['name'] == nome or cliente['federation_subscription_number'] == nome
9
8
  mid = cliente['id']
@@ -19,6 +18,8 @@ module Myfinance
19
18
  response['entity']
20
19
  end
21
20
 
22
-
21
+ def self.entidades
22
+ lget '/entities.json'
23
+ end
23
24
  end
24
25
 
@@ -1,3 +1,3 @@
1
1
  module Myfinance
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -16,5 +16,9 @@ describe 'Manipulando Pessoas', type: :feature do
16
16
  expect(centro_de_receita_id).to be_nil
17
17
  end
18
18
 
19
-
19
+ it '#categorias' do
20
+ double categorias_double = double('categorias_double')
21
+ expect(Myfinance).to receive(:lget).once.with('/categories.json').and_return categorias_double
22
+ expect(Myfinance.categorias).to eql(categorias_double)
23
+ end
20
24
  end
@@ -0,0 +1,90 @@
1
+ describe "Manipulando Centros de Receita e Custo", type: :feature do
2
+
3
+ require "myfinance"
4
+
5
+ let(:centers) {
6
+ [
7
+ {"classification_center" => {"cost_center" => true, "created_at" => "2013-05-21T17:05:14-03:00", "entity_id" => 14618, "excel_import_id" => nil, "guid" => nil, "id" => 94150, "imported_from_sync" => false, "modified_by_sync" => false, "name" => "Despesas Marketing", "revenue_center" => false, "updated_at" => "2013-05-21T17:05:14-03:00", "use_count" => 0}},
8
+ {"classification_center" => {"cost_center" => true, "created_at" => "2013-05-21T17:07:04-03:00", "entity_id" => 14618, "excel_import_id" => nil, "guid" => nil, "id" => 94152, "imported_from_sync" => false, "modified_by_sync" => false, "name" => "Despesas Producao TI", "revenue_center" => false, "updated_at" => "2013-05-21T17:07:04-03:00", "use_count" => 2}},
9
+ {"classification_center" => {"cost_center" => false, "created_at" => "2013-07-25T17:06:28-03:00", "entity_id" => 14618, "excel_import_id" => nil, "guid" => nil, "id" => 108858, "imported_from_sync" => false, "modified_by_sync" => false, "name" => "Receita de Marketing", "revenue_center" => true, "updated_at" => "2013-07-25T17:06:28-03:00", "use_count" => 23}},
10
+ {"classification_center" => {"cost_center" => false, "created_at" => "2014-11-05T11:10:42-02:00", "entity_id" => 20341, "excel_import_id" => nil, "guid" => nil, "id" => 173848, "imported_from_sync" => false, "modified_by_sync" => false, "name" => "Receita Total", "revenue_center" => true, "updated_at" => "2014-11-05T11:10:42-02:00", "use_count" => 1}}
11
+ ]
12
+ }
13
+
14
+ describe "#centros" do
15
+ it "sem filtro" do
16
+ expect(Myfinance).to receive(:classification_centers).once.and_return(centers)
17
+ centros = Myfinance.centros
18
+ expect(centros.size).to eql(4)
19
+ expect(centros[0]["classification_center"]["id"]).to eql(94150)
20
+ expect(centros[1]["classification_center"]["id"]).to eql(94152)
21
+ expect(centros[2]["classification_center"]["id"]).to eql(108858)
22
+ expect(centros[3]["classification_center"]["id"]).to eql(173848)
23
+ end
24
+ it "somente custo" do
25
+ expect(Myfinance).to receive(:classification_centers).once.and_return(centers)
26
+ centros = Myfinance.centros(true)
27
+ expect(centros.size).to eql(2)
28
+ expect(centros[0]["classification_center"]["id"]).to eql(94150)
29
+ expect(centros[1]["classification_center"]["id"]).to eql(94152)
30
+ end
31
+ it "somente receita" do
32
+ expect(Myfinance).to receive(:classification_centers).once.and_return(centers)
33
+ centros = Myfinance.centros(false)
34
+ expect(centros.size).to eql(2)
35
+ expect(centros[0]["classification_center"]["id"]).to eql(108858)
36
+ expect(centros[1]["classification_center"]["id"]).to eql(173848)
37
+ end
38
+ end
39
+
40
+ describe "#centro_id" do
41
+ describe "sem filtro" do
42
+ it "encontrado" do
43
+ expect(Myfinance).to receive(:classification_centers).once.and_return(centers)
44
+ expect(Myfinance.centro_id("Despesas Producao TI")).to eql(94152)
45
+ end
46
+ it "nao encontrado" do
47
+ expect(Myfinance).to receive(:classification_centers).once.and_return(centers)
48
+ expect(Myfinance.centro_id("XYZ")).to be_nil
49
+ end
50
+ end
51
+ describe "somente custo" do
52
+ it "encontrado" do
53
+ expect(Myfinance).to receive(:classification_centers).once.and_return(centers)
54
+ expect(Myfinance.centro_id("Despesas Producao TI", true)).to eql(94152)
55
+ end
56
+ it "nao encontrado" do
57
+ expect(Myfinance).to receive(:classification_centers).once.and_return(centers)
58
+ expect(Myfinance.centro_id("Receita de Marketing", true)).to be_nil
59
+ end
60
+ end
61
+ describe "somente receita" do
62
+ it "encontrado" do
63
+ expect(Myfinance).to receive(:classification_centers).once.and_return(centers)
64
+ expect(Myfinance.centro_id("Despesas Producao TI", false)).to be_nil
65
+ end
66
+ it "nao encontrado" do
67
+ expect(Myfinance).to receive(:classification_centers).once.and_return(centers)
68
+ expect(Myfinance.centro_id("Receita de Marketing", false)).to eql(108858)
69
+ end
70
+ end
71
+ end
72
+
73
+ it "#centro_de_receita_id" do
74
+ double id_double = double("id_double")
75
+ expect(Myfinance).to receive(:centro_id).once.with("nome", false).and_return id_double
76
+ expect(Myfinance.centro_de_receita_id("nome")).to eql(id_double)
77
+ end
78
+
79
+ it "#centro_de_custo_id" do
80
+ double id_double = double("id_double")
81
+ expect(Myfinance).to receive(:centro_id).once.with("nome", true).and_return id_double
82
+ expect(Myfinance.centro_de_custo_id("nome")).to eql(id_double)
83
+ end
84
+
85
+ it "#classification_centers" do
86
+ double classification_centers_double = double("classification_centers_double")
87
+ expect(Myfinance).to receive(:lget).once.with("/classification_centers.json").and_return classification_centers_double
88
+ expect(Myfinance.classification_centers).to eql(classification_centers_double)
89
+ end
90
+ end
@@ -63,7 +63,9 @@ describe 'Manipulando Contas a Receber', type: :feature do
63
63
  expect(conta_a_receber['receivable_account']).to_not be_nil
64
64
  end
65
65
 
66
-
67
-
68
-
66
+ it '#conta_a_receber' do
67
+ double conta_a_receber_double = double('conta_a_receber_double')
68
+ expect(Myfinance).to receive(:lget).once.with("/entities/2/receivable_accounts/1.json").and_return conta_a_receber_double
69
+ expect(Myfinance.conta_a_receber(1,2)).to eql(conta_a_receber_double)
70
+ end
69
71
  end
@@ -17,4 +17,9 @@ describe 'Manipulando Entidades', type: :feature do
17
17
  expect(entidade['deleted_at']).to be_nil
18
18
  end
19
19
 
20
+ it '#entidades' do
21
+ double entidades_double = double('entidades_double')
22
+ expect(Myfinance).to receive(:lget).once.with('/entities.json').and_return entidades_double
23
+ expect(Myfinance.entidades).to eql(entidades_double)
24
+ end
20
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myfinance-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Lopes Neto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-24 00:00:00.000000000 Z
11
+ date: 2015-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,6 +91,7 @@ files:
91
91
  - lib/myfinance/version.rb
92
92
  - myfinance-rails.gemspec
93
93
  - spec/features/categoria_spec.rb
94
+ - spec/features/centro_receita_custo_spec.rb
94
95
  - spec/features/contas_a_receber_spec.rb
95
96
  - spec/features/entidades_spec.rb
96
97
  - spec/features/imposto_spec.rb
@@ -122,6 +123,7 @@ specification_version: 4
122
123
  summary: GEM para facilitar a uso da API do Myfinance em Aplicativos Rails
123
124
  test_files:
124
125
  - spec/features/categoria_spec.rb
126
+ - spec/features/centro_receita_custo_spec.rb
125
127
  - spec/features/contas_a_receber_spec.rb
126
128
  - spec/features/entidades_spec.rb
127
129
  - spec/features/imposto_spec.rb