br_nfe 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +0 -1
  4. data/Gemfile.lock +1 -1
  5. data/README.markdown +264 -106
  6. data/lib/br_nfe/{helper → association}/have_address.rb +1 -1
  7. data/lib/br_nfe/{helper → association}/have_condicao_pagamento.rb +1 -1
  8. data/lib/br_nfe/association/have_destinatario.rb +22 -0
  9. data/lib/br_nfe/association/have_emitente.rb +24 -0
  10. data/lib/br_nfe/base.rb +37 -27
  11. data/lib/br_nfe/condicao_pagamento.rb +2 -0
  12. data/lib/br_nfe/constants.rb +33 -0
  13. data/lib/br_nfe/endereco.rb +10 -0
  14. data/lib/br_nfe/helper/string_methods.rb +4 -0
  15. data/lib/br_nfe/{emitente.rb → person.rb} +11 -7
  16. data/lib/br_nfe/product/base.rb +82 -0
  17. data/lib/br_nfe/product/consulta_status_servico.rb +35 -0
  18. data/lib/br_nfe/product/emitente.rb +8 -0
  19. data/lib/br_nfe/product/gateway/base.rb +62 -0
  20. data/lib/br_nfe/product/gateway/web_service_svrs.rb +39 -0
  21. data/lib/br_nfe/product/value_nf.rb +9 -0
  22. data/lib/br_nfe/product/xml/soap_env.xml.slim +8 -0
  23. data/lib/br_nfe/product/xml/v3_10/XSD/consReciNFe_v3.10.xsd +9 -0
  24. data/lib/br_nfe/product/xml/v3_10/XSD/consSitNFe_v3.10.xsd +9 -0
  25. data/lib/br_nfe/product/xml/v3_10/XSD/consStatServ_v3.10.xsd +9 -0
  26. data/lib/br_nfe/product/xml/v3_10/XSD/enviNFe_v3.10.xsd +9 -0
  27. data/lib/br_nfe/product/xml/v3_10/XSD/inutNFe_v3.10.xsd +9 -0
  28. data/lib/br_nfe/product/xml/v3_10/XSD/leiauteConsSitNFe_v3.10.xsd +502 -0
  29. data/lib/br_nfe/product/xml/v3_10/XSD/leiauteConsStatServ_v3.10.xsd +98 -0
  30. data/lib/br_nfe/product/xml/v3_10/XSD/leiauteInutNFe_v3.10.xsd +193 -0
  31. data/lib/br_nfe/product/xml/v3_10/XSD/leiauteNFe_v3.10.xsd +6060 -0
  32. data/lib/br_nfe/product/xml/v3_10/XSD/nfe_v3.10.xsd +9 -0
  33. data/lib/br_nfe/product/xml/v3_10/XSD/procInutNFe_v3.10.xsd +9 -0
  34. data/lib/br_nfe/product/xml/v3_10/XSD/procNFe_v3.10.xsd +9 -0
  35. data/lib/br_nfe/product/xml/v3_10/XSD/retConsReciNFe_v3.10.xsd +9 -0
  36. data/lib/br_nfe/product/xml/v3_10/XSD/retConsSitNFe_v3.10.xsd +9 -0
  37. data/lib/br_nfe/product/xml/v3_10/XSD/retConsStatServ_v3.10.xsd +9 -0
  38. data/lib/br_nfe/product/xml/v3_10/XSD/retEnviNFe_v3.10.xsd +9 -0
  39. data/lib/br_nfe/product/xml/v3_10/XSD/retInutNFe_v3.10.xsd +9 -0
  40. data/lib/br_nfe/product/xml/v3_10/XSD/tiposBasico_v3.10.xsd +571 -0
  41. data/lib/br_nfe/product/xml/v3_10/XSD/xmldsig-core-schema_v1.01.xsd +98 -0
  42. data/lib/br_nfe/product/xml/v3_10/consulta_status_servico.xml.slim +4 -0
  43. data/lib/br_nfe/service/association/have_intermediario.rb +26 -0
  44. data/lib/br_nfe/service/association/have_rps.rb +36 -0
  45. data/lib/br_nfe/service/base.rb +24 -20
  46. data/lib/br_nfe/service/betha/v1/cancela_nfse.rb +43 -0
  47. data/lib/br_nfe/service/betha/v1/consulta_lote_rps.rb +20 -6
  48. data/lib/br_nfe/service/betha/v1/consulta_nfs_por_rps.rb +17 -6
  49. data/lib/br_nfe/service/betha/v1/consulta_nfse.rb +16 -5
  50. data/lib/br_nfe/service/betha/v1/consulta_situacao_lote_rps.rb +15 -6
  51. data/lib/br_nfe/service/betha/v1/gateway.rb +4 -0
  52. data/lib/br_nfe/service/betha/v1/recepcao_lote_rps.rb +13 -5
  53. data/lib/br_nfe/service/betha/v1/xml/_tc_identificacao_prestador.xml.slim +3 -0
  54. data/lib/br_nfe/service/betha/v1/xml/_tc_pedido_cancelamento.xml.slim +4 -0
  55. data/lib/br_nfe/service/concerns/rules/cancelamento_nfs.rb +8 -0
  56. data/lib/br_nfe/service/concerns/rules/consulta_nfs_por_rps.rb +1 -1
  57. data/lib/br_nfe/service/concerns/rules/consulta_nfse.rb +5 -2
  58. data/lib/br_nfe/service/concerns/values_ts/service_v1.rb +319 -0
  59. data/lib/br_nfe/service/destinatario.rb +7 -0
  60. data/lib/br_nfe/service/emitente.rb +8 -0
  61. data/lib/br_nfe/service/intermediario.rb +1 -12
  62. data/lib/br_nfe/service/item.rb +7 -7
  63. data/lib/br_nfe/service/response/build/base.rb +166 -0
  64. data/lib/br_nfe/service/response/build/cancelamento.rb +62 -0
  65. data/lib/br_nfe/service/response/build/consulta_lote_rps.rb +25 -0
  66. data/lib/br_nfe/service/response/build/consulta_nfs_por_rps.rb +25 -0
  67. data/lib/br_nfe/service/response/build/consulta_nfse.rb +24 -0
  68. data/lib/br_nfe/service/response/build/consulta_situacao_lote_rps.rb +56 -0
  69. data/lib/br_nfe/service/response/build/invoice_build.rb +359 -0
  70. data/lib/br_nfe/service/response/build/recepcao_lote_rps.rb +69 -0
  71. data/lib/br_nfe/service/response/cancelamento.rb +22 -0
  72. data/lib/br_nfe/service/response/consulta_lote_rps.rb +18 -0
  73. data/lib/br_nfe/service/response/consulta_nfs_por_rps.rb +10 -0
  74. data/lib/br_nfe/service/response/consulta_nfse.rb +10 -0
  75. data/lib/br_nfe/service/response/consulta_situacao_lote_rps.rb +74 -0
  76. data/lib/br_nfe/service/response/default.rb +93 -0
  77. data/lib/br_nfe/{response/service → service/response}/nota_fiscal.rb +19 -12
  78. data/lib/br_nfe/service/response/paths/v1/tc_nfse.rb +275 -0
  79. data/lib/br_nfe/service/response/recepcao_lote_rps.rb +35 -0
  80. data/lib/br_nfe/service/rps.rb +30 -27
  81. data/lib/br_nfe/service/sc/florianopolis/xml/_service_item.xml.slim +4 -4
  82. data/lib/br_nfe/service/sc/florianopolis/xml/inf_requisicao.xml.slim +4 -4
  83. data/lib/br_nfe/service/simpliss/v1/cancela_nfse.rb +16 -6
  84. data/lib/br_nfe/service/simpliss/v1/consulta_lote_rps.rb +20 -12
  85. data/lib/br_nfe/service/simpliss/v1/consulta_nfs_por_rps.rb +21 -6
  86. data/lib/br_nfe/service/simpliss/v1/consulta_nfse.rb +20 -6
  87. data/lib/br_nfe/service/simpliss/v1/consulta_situacao_lote_rps.rb +17 -6
  88. data/lib/br_nfe/service/simpliss/v1/recepcao_lote_rps.rb +16 -4
  89. data/lib/br_nfe/service/simpliss/v1/xml/_tc_item_servico.xml.slim +2 -2
  90. data/lib/br_nfe/service/thema/v1/cancela_nfse.rb +21 -19
  91. data/lib/br_nfe/service/thema/v1/consulta_lote_rps.rb +21 -19
  92. data/lib/br_nfe/service/thema/v1/consulta_nfs_por_rps.rb +25 -18
  93. data/lib/br_nfe/service/thema/v1/consulta_nfse.rb +20 -20
  94. data/lib/br_nfe/service/thema/v1/consulta_situacao_lote_rps.rb +14 -20
  95. data/lib/br_nfe/service/thema/v1/recepcao_lote_rps.rb +11 -16
  96. data/lib/br_nfe/service/thema/v1/recepcao_lote_rps_limitado.rb +8 -6
  97. data/lib/br_nfe/service/xml/v1/_tc_identificacao_nfse.xml.slim +1 -1
  98. data/lib/br_nfe/service/xml/v1/_tc_pedido_cancelamento.xml.slim +1 -1
  99. data/lib/br_nfe/service/xml/v1/_tc_valores.xml.slim +11 -11
  100. data/lib/br_nfe/version.rb +1 -1
  101. data/lib/br_nfe.rb +62 -62
  102. data/test/br_nfe/association/have_address_test.rb +64 -0
  103. data/test/br_nfe/association/have_condicao_pagamento_test.rb +75 -0
  104. data/test/br_nfe/association/have_destinatario_test.rb +76 -0
  105. data/test/br_nfe/association/have_emitente_test.rb +80 -0
  106. data/test/br_nfe/base_test.rb +96 -61
  107. data/test/br_nfe/endereco_test.rb +21 -0
  108. data/test/br_nfe/person_test.rb +55 -0
  109. data/test/br_nfe/product/base_test.rb +150 -0
  110. data/test/br_nfe/product/consulta_status_servico_test.rb +59 -0
  111. data/test/br_nfe/product/emitente_test.rb +29 -0
  112. data/test/br_nfe/product/gateway/base_test.rb +16 -0
  113. data/test/br_nfe/product/gateway/web_service_svrs_test.rb +36 -0
  114. data/test/br_nfe/service/association/have_intermediario_test.rb +80 -0
  115. data/test/br_nfe/service/association/have_rps_test.rb +62 -0
  116. data/test/br_nfe/service/base_test.rb +42 -42
  117. data/test/br_nfe/service/betha/v1/cancela_nfse_test.rb +90 -0
  118. data/test/br_nfe/service/betha/v1/consulta_lote_rps_test.rb +105 -5
  119. data/test/br_nfe/service/betha/v1/consulta_nfs_por_rps_test.rb +103 -5
  120. data/test/br_nfe/service/betha/v1/consulta_nfse_test.rb +114 -5
  121. data/test/br_nfe/service/betha/v1/consulta_situacao_lote_rps_test.rb +118 -5
  122. data/test/br_nfe/service/betha/v1/gateway_test.rb +1 -1
  123. data/test/br_nfe/service/betha/v1/recepcao_lote_rps_test.rb +51 -5
  124. data/test/br_nfe/service/concerns/rules/cancelamento_nfs_test.rb +2 -2
  125. data/test/br_nfe/service/concerns/rules/consulta_nfs_por_rps_test.rb +2 -7
  126. data/test/br_nfe/service/concerns/rules/consulta_nfse_test.rb +24 -3
  127. data/test/br_nfe/service/concerns/rules/recepcao_lote_rps_test.rb +1 -1
  128. data/test/br_nfe/{helper → service/concerns}/values_ts/service_v1_test.rb +2 -2
  129. data/test/br_nfe/{destinatario_test.rb → service/destinatario_test.rb} +3 -4
  130. data/test/br_nfe/service/emitente_test.rb +29 -0
  131. data/test/br_nfe/service/item_test.rb +14 -14
  132. data/test/br_nfe/service/response/build/base_test.rb +80 -0
  133. data/test/br_nfe/{response/service → service/response}/default_test.rb +1 -82
  134. data/test/br_nfe/service/response/nota_fiscal_test.rb +59 -0
  135. data/test/br_nfe/{response/service → service/response}/paths/v1/tc_nfse_test.rb +10 -10
  136. data/test/br_nfe/service/rps_test.rb +107 -138
  137. data/test/br_nfe/service/sc/florianopolis/emission_rps_test.rb +9 -9
  138. data/test/br_nfe/service/simpliss/v1/base_test.rb +1 -1
  139. data/test/br_nfe/service/simpliss/v1/cancela_nfse_test.rb +7 -10
  140. data/test/br_nfe/service/simpliss/v1/consulta_lote_rps_test.rb +11 -18
  141. data/test/br_nfe/service/simpliss/v1/consulta_nfs_por_rps_test.rb +11 -18
  142. data/test/br_nfe/service/simpliss/v1/consulta_nfse_test.rb +11 -18
  143. data/test/br_nfe/service/simpliss/v1/consulta_situacao_lote_rps_test.rb +7 -11
  144. data/test/br_nfe/service/simpliss/v1/recepcao_lote_rps_test.rb +3 -9
  145. data/test/br_nfe/service/thema/v1/base_test.rb +1 -1
  146. data/test/br_nfe/service/thema/v1/cancela_nfse_test.rb +7 -14
  147. data/test/br_nfe/service/thema/v1/consulta_lote_rps_test.rb +6 -17
  148. data/test/br_nfe/service/thema/v1/consulta_nfs_por_rps_test.rb +6 -13
  149. data/test/br_nfe/service/thema/v1/consulta_nfse_test.rb +11 -18
  150. data/test/br_nfe/service/thema/v1/consulta_situacao_lote_rps_test.rb +7 -11
  151. data/test/br_nfe/service/thema/v1/recepcao_lote_rps_limitado_test.rb +1 -5
  152. data/test/br_nfe/service/thema/v1/recepcao_lote_rps_test.rb +3 -9
  153. data/test/factories/base.rb +0 -1
  154. data/test/factories/{emitente.rb → person.rb} +1 -1
  155. data/test/factories/product/base.rb +12 -0
  156. data/test/factories/product/consulta_status_servico.rb +12 -0
  157. data/test/factories/product/emitente.rb +15 -0
  158. data/test/factories/product/gateway/base.rb +5 -0
  159. data/test/factories/product/gateway/web_service_svrs.rb +5 -0
  160. data/test/factories/service/betha/v1/{cancelamento_nfs.rb → cancela_nfse.rb} +2 -1
  161. data/test/factories/service/betha/v1/consulta_lote_rps.rb +1 -1
  162. data/test/factories/service/betha/v1/consulta_nfs_por_rps.rb +1 -1
  163. data/test/factories/service/betha/v1/consulta_nfse.rb +1 -1
  164. data/test/factories/service/betha/v1/consulta_situacao_lote_rps.rb +1 -1
  165. data/test/factories/{destinatario.rb → service/destinatario.rb} +1 -1
  166. data/test/factories/service/emitente.rb +15 -0
  167. data/test/factories/service/item.rb +4 -4
  168. data/test/factories/service/response/build_response.rb +5 -0
  169. data/test/factories/service/response/default.rb +6 -0
  170. data/test/factories/{response/service → service/response}/nota_fiscal.rb +8 -8
  171. data/test/factories/service/rps.rb +11 -11
  172. data/test/factories/service/sc/florianopolis/base.rb +1 -1
  173. data/test/factories/service/sc/florianopolis/cancellation.rb +1 -1
  174. data/test/factories/service/sc/florianopolis/emission_rps.rb +1 -1
  175. data/test/factories/service/simpliss/v1/base.rb +1 -1
  176. data/test/factories/service/simpliss/v1/cancela_nfse.rb +1 -1
  177. data/test/factories/service/simpliss/v1/consulta_lote_rps.rb +1 -1
  178. data/test/factories/service/simpliss/v1/consulta_nfs_por_rps.rb +1 -1
  179. data/test/factories/service/simpliss/v1/consulta_nfse.rb +1 -1
  180. data/test/factories/service/simpliss/v1/consulta_situacao_lote_rps.rb +1 -1
  181. data/test/factories/service/simpliss/v1/recepcao_lote_rps.rb +1 -1
  182. data/test/factories/service/thema/v1/base.rb +1 -1
  183. data/test/factories/service/thema/v1/cancela_nfse.rb +1 -1
  184. data/test/factories/service/thema/v1/consulta_lote_rps.rb +1 -1
  185. data/test/factories/service/thema/v1/consulta_nfs_por_rps.rb +1 -1
  186. data/test/factories/service/thema/v1/consulta_nfse.rb +1 -1
  187. data/test/factories/service/thema/v1/consulta_situacao_lote_rps.rb +1 -1
  188. data/test/factories/service/thema/v1/recepcao_lote_rps.rb +1 -1
  189. data/test/fixtures/service/response/betha/v1/cancela_nfse/fault.xml +17 -0
  190. data/test/fixtures/service/response/betha/v1/cancela_nfse/success.xml +48 -0
  191. data/test/fixtures/service/response/betha/v1/consulta_lote_rps/fault.xml +18 -0
  192. data/test/fixtures/service/response/betha/v1/consulta_lote_rps/success.xml +108 -0
  193. data/test/fixtures/service/response/betha/v1/consulta_nfse/fault.xml +18 -0
  194. data/test/fixtures/service/response/betha/v1/consulta_nfse/nfs_empty.xml +12 -0
  195. data/test/fixtures/service/response/betha/v1/consulta_nfse/success.xml +115 -0
  196. data/test/fixtures/service/response/betha/v1/consulta_nfse_por_rps/fault.xml +18 -0
  197. data/test/fixtures/service/response/betha/v1/consulta_nfse_por_rps/success.xml +103 -0
  198. data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/error.xml +13 -0
  199. data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/fault.xml +17 -0
  200. data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/success.xml +13 -0
  201. data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unprocessed.xml +13 -0
  202. data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unprocessed_by_code_error.xml +17 -0
  203. data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unreceived.xml +13 -0
  204. data/test/fixtures/service/response/betha/v1/consulta_situacao_lote_rps/unreceived_by_code_error.xml +17 -0
  205. data/test/fixtures/service/response/betha/v1/recepcao_lote_rps/error.xml +17 -0
  206. data/test/fixtures/service/response/betha/v1/recepcao_lote_rps/success.xml +14 -0
  207. metadata +160 -94
  208. data/lib/br_nfe/destinatario.rb +0 -26
  209. data/lib/br_nfe/helper/have_destinatario.rb +0 -18
  210. data/lib/br_nfe/helper/have_emitente.rb +0 -20
  211. data/lib/br_nfe/helper/have_intermediario.rb +0 -24
  212. data/lib/br_nfe/helper/have_rps.rb +0 -34
  213. data/lib/br_nfe/helper/values_ts/service_v1.rb +0 -317
  214. data/lib/br_nfe/response/service/build_response.rb +0 -463
  215. data/lib/br_nfe/response/service/default.rb +0 -185
  216. data/lib/br_nfe/response/service/paths/base.rb +0 -127
  217. data/lib/br_nfe/response/service/paths/v1/servico_cancelar_nfse_resposta.rb +0 -22
  218. data/lib/br_nfe/response/service/paths/v1/servico_consultar_lote_rps_resposta.rb +0 -25
  219. data/lib/br_nfe/response/service/paths/v1/servico_consultar_nfse_resposta.rb +0 -25
  220. data/lib/br_nfe/response/service/paths/v1/servico_consultar_nfse_rps_resposta.rb +0 -25
  221. data/lib/br_nfe/response/service/paths/v1/servico_consultar_situacao_lote_rps_resposta.rb +0 -31
  222. data/lib/br_nfe/response/service/paths/v1/servico_enviar_lote_rps_resposta.rb +0 -36
  223. data/lib/br_nfe/response/service/paths/v1/tc_nfse.rb +0 -271
  224. data/lib/br_nfe/service/betha/v1/cancelamento_nfs.rb +0 -36
  225. data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_lote_rps_resposta.rb +0 -23
  226. data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_resposta.rb +0 -21
  227. data/lib/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +0 -21
  228. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_cancelar_nfse_resposta.rb +0 -22
  229. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_lote_rps_resposta.rb +0 -25
  230. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_nfse_resposta.rb +0 -25
  231. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +0 -25
  232. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_consultar_situacao_lote_rps_resposta.rb +0 -31
  233. data/lib/br_nfe/service/simpliss/v1/response_paths/servico_enviar_lote_rps_resposta.rb +0 -36
  234. data/lib/br_nfe/service/thema/v1/response_paths/servico_cancelar_nfse_resposta.rb +0 -17
  235. data/lib/br_nfe/service/thema/v1/response_paths/servico_consultar_nfse_rps_resposta.rb +0 -19
  236. data/test/br_nfe/emitente_test.rb +0 -46
  237. data/test/br_nfe/helper/have_address_test.rb +0 -62
  238. data/test/br_nfe/helper/have_condicao_pagamento_test.rb +0 -71
  239. data/test/br_nfe/helper/have_destinatario_test.rb +0 -64
  240. data/test/br_nfe/helper/have_emitente_test.rb +0 -63
  241. data/test/br_nfe/helper/have_intermediario_test.rb +0 -77
  242. data/test/br_nfe/helper/have_rps_test.rb +0 -59
  243. data/test/br_nfe/response/service/build_response_test.rb +0 -205
  244. data/test/br_nfe/response/service/nota_fiscal_test.rb +0 -41
  245. data/test/br_nfe/response/service/paths/base_test.rb +0 -196
  246. data/test/br_nfe/response/service/paths/v1/servico_cancelar_nfse_resposta_test.rb +0 -25
  247. data/test/br_nfe/response/service/paths/v1/servico_consultar_lote_rps_resposta_test.rb +0 -30
  248. data/test/br_nfe/response/service/paths/v1/servico_consultar_nfse_resposta_test.rb +0 -30
  249. data/test/br_nfe/response/service/paths/v1/servico_consultar_nfse_rps_resposta_test.rb +0 -30
  250. data/test/br_nfe/response/service/paths/v1/servico_consultar_situacao_lote_rps_resposta_test.rb +0 -30
  251. data/test/br_nfe/response/service/paths/v1/servico_enviar_lote_rps_resposta_test.rb +0 -34
  252. data/test/br_nfe/service/betha/v1/cancelamento_nfs_test.rb +0 -54
  253. data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_lote_rps_resposta_test.rb +0 -16
  254. data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_resposta_test.rb +0 -16
  255. data/test/br_nfe/service/betha/v1/response_paths/servico_consultar_nfse_rps_resposta_test.rb +0 -16
  256. data/test/factories/response/service/build_response.rb +0 -5
  257. data/test/factories/response/service/default.rb +0 -10
@@ -1,9 +1,38 @@
1
1
  require 'test_helper'
2
- require 'br_nfe/helper/have_emitente_test'
3
2
 
4
3
  describe BrNfe::Base do
5
4
  subject { FactoryGirl.build(:br_nfe_base, emitente: emitente) }
6
- let(:emitente) { FactoryGirl.build(:emitente) }
5
+ let(:emitente) { FactoryGirl.build(:person) }
6
+
7
+ before do
8
+ BrNfe::Base.any_instance.stubs(:emitente_class).returns(BrNfe::Person)
9
+ end
10
+
11
+ describe "#ibge_code_of_issuer_city" do
12
+ it "se não setar um valor deve pegar o valor do codigo IBGE do endereço do emitente" do
13
+ subject.emitente.endereco.codigo_municipio = '12345678'
14
+ subject.ibge_code_of_issuer_city = nil
15
+ subject.ibge_code_of_issuer_city.must_equal '12345678'
16
+ end
17
+ it "se setar o valor em ibge_code_of_issuer_city não deve pegar do endereço do emitente" do
18
+ subject.emitente.endereco.codigo_municipio = '12345678'
19
+ subject.ibge_code_of_issuer_city = 78978945
20
+ subject.ibge_code_of_issuer_city.must_equal '78978945'
21
+ end
22
+ end
23
+
24
+ describe "#ibge_code_of_issuer_uf" do
25
+ it "se não setar um valor deve pegar o valor do codigo IBGE do endereço do emitente" do
26
+ subject.emitente.endereco.codigo_ibge_uf = '42'
27
+ subject.ibge_code_of_issuer_uf = nil
28
+ subject.ibge_code_of_issuer_uf.must_equal '42'
29
+ end
30
+ it "se setar o valor em ibge_code_of_issuer_uf não deve pegar do endereço do emitente" do
31
+ subject.emitente.endereco.codigo_ibge_uf = '43'
32
+ subject.ibge_code_of_issuer_uf = 42
33
+ subject.ibge_code_of_issuer_uf.must_equal '42'
34
+ end
35
+ end
7
36
 
8
37
  describe "validations" do
9
38
  context "obrigatoriedade do certificado" do
@@ -41,7 +70,9 @@ describe BrNfe::Base do
41
70
  end
42
71
 
43
72
  describe "#emitente" do
44
- include BrNfeTest::HelperTest::HaveEmitenteTest
73
+ it "deve conter o module HaveEmitente" do
74
+ subject.class.included_modules.must_include BrNfe::Association::HaveEmitente
75
+ end
45
76
  end
46
77
 
47
78
  describe "#env" do
@@ -172,34 +203,78 @@ describe BrNfe::Base do
172
203
  end
173
204
  end
174
205
 
206
+ describe "ssl_version" do
207
+ it "por padrão deve retornar :SSLv3" do
208
+ subject.ssl_version.must_equal :SSLv3
209
+ end
210
+ end
211
+
212
+ describe '#ssl_request?' do
213
+ it "por padrão não deve instanciar o client_wsdl com ssl" do
214
+ subject.ssl_request?.must_equal false
215
+ end
216
+ end
217
+
175
218
  describe "#client_wsdl" do
176
219
  it "deve instanciar um Savon.client com a configuração adequada" do
177
220
  # Stub metodos para configuração do client WSDL
178
221
  subject.expects(:wsdl).returns('wsdl')
179
222
 
180
- subject.client_wsdl_ssl_verify_mode = 'client_wsdl_ssl_verify_mode'
181
- subject.client_wsdl_ssl_cert_file = 'client_wsdl_ssl_cert_file'
182
- subject.client_wsdl_ssl_cert_key_file = 'client_wsdl_ssl_cert_key_file'
183
- subject.client_wsdl_ssl_cert_key_password = 'client_wsdl_ssl_cert_key_password'
223
+ # Ajusto a configuração da gem para testar
224
+ BrNfe.stubs(:client_wsdl_log).returns('client_wsdl_log')
225
+ BrNfe.stubs(:client_wsdl_pretty_print_xml).returns('client_wsdl_pretty_print_xml')
226
+ # Não deve pegar o certificado para configurar o client
227
+ subject.expects(:ssl_version).never
228
+ subject.expects(:certificate).never
229
+ subject.expects(:certificate_key).never
230
+ subject.expects(:certificate_pkcs12_password).never
231
+
232
+ subject.instance_variable_get(:@client_wsdl).must_be_nil
233
+
234
+ client_wsdl = subject.client_wsdl
235
+
236
+ client_wsdl.globals[:wsdl].must_equal 'wsdl'
237
+ client_wsdl.globals[:log].must_equal 'client_wsdl_log'
238
+ client_wsdl.globals[:pretty_print_xml].must_equal 'client_wsdl_pretty_print_xml'
239
+ client_wsdl.globals[:ssl_verify_mode].must_equal :none
240
+
241
+ client_wsdl.globals[:ssl_version].must_be_nil
242
+ client_wsdl.globals[:ssl_cert].must_be_nil
243
+ client_wsdl.globals[:ssl_cert_key].must_be_nil
244
+ client_wsdl.globals[:ssl_cert_key_password].must_be_nil
245
+
246
+ subject.instance_variable_get(:@client_wsdl).must_equal client_wsdl
247
+ end
248
+
249
+ it "se ssl_request? for true então deve instanciar um Savon.client com a configuração de SSL" do
250
+ # Stub metodos para configuração do client WSDL
251
+ subject.expects(:wsdl).returns('wsdl')
184
252
 
185
253
  # Ajusto a configuração da gem para testar
186
- BrNfe.client_wsdl_log = 'client_wsdl_log'
187
- BrNfe.client_wsdl_pretty_print_xml = 'client_wsdl_pretty_print_xml'
254
+ BrNfe.stubs(:client_wsdl_log).returns('client_wsdl_log')
255
+ BrNfe.stubs(:client_wsdl_pretty_print_xml).returns('client_wsdl_pretty_print_xml')
256
+ # Não deve pegar o certificado para configurar o client
257
+ subject.expects(:ssl_version).returns(:TLSv1)
258
+ subject.expects(:certificate).returns(:certificate)
259
+ subject.expects(:certificate_key).returns(:certificate_key)
260
+ subject.expects(:certificate_pkcs12_password).returns(:certificate_pkcs12_password)
261
+ subject.expects(:ssl_request?).returns(true)
188
262
 
189
263
  subject.instance_variable_get(:@client_wsdl).must_be_nil
190
264
 
191
- Savon.expects(:client).with({
192
- wsdl: 'wsdl',
193
- log: 'client_wsdl_log',
194
- pretty_print_xml: 'client_wsdl_pretty_print_xml',
195
- ssl_verify_mode: 'client_wsdl_ssl_verify_mode',
196
- ssl_cert_file: 'client_wsdl_ssl_cert_file',
197
- ssl_cert_key_file: 'client_wsdl_ssl_cert_key_file',
198
- ssl_cert_key_password: 'client_wsdl_ssl_cert_key_password'
199
- }).returns('client wsdl')
200
-
201
- subject.client_wsdl.must_equal 'client wsdl'
202
- subject.instance_variable_get(:@client_wsdl).must_equal 'client wsdl'
265
+ client_wsdl = subject.client_wsdl
266
+
267
+ client_wsdl.globals[:wsdl].must_equal 'wsdl'
268
+ client_wsdl.globals[:log].must_equal 'client_wsdl_log'
269
+ client_wsdl.globals[:pretty_print_xml].must_equal 'client_wsdl_pretty_print_xml'
270
+ client_wsdl.globals[:ssl_verify_mode].must_equal :none
271
+
272
+ client_wsdl.globals[:ssl_version].must_equal :TLSv1
273
+ client_wsdl.globals[:ssl_cert].must_equal :certificate
274
+ client_wsdl.globals[:ssl_cert_key].must_equal :certificate_key
275
+ client_wsdl.globals[:ssl_cert_key_password].must_equal :certificate_pkcs12_password
276
+
277
+ subject.instance_variable_get(:@client_wsdl).must_equal client_wsdl
203
278
  end
204
279
  it "se ja tiver valor na variavel @client_wsdl deve manter esse valor" do
205
280
  Savon.expects(:client).never
@@ -209,46 +284,6 @@ describe BrNfe::Base do
209
284
  end
210
285
  end
211
286
 
212
- describe '#client_wsdl_ssl_verify_mode' do
213
- it "se eu setar um valor deve retornar esse valor" do
214
- subject.client_wsdl_ssl_verify_mode = :value_client_wsdl_ssl_verify_mode
215
- subject.client_wsdl_ssl_verify_mode.must_equal :value_client_wsdl_ssl_verify_mode
216
- end
217
- it "se não setar nenhum valor deve retornar o valor da configuração" do
218
- subject.class.new.client_wsdl_ssl_verify_mode.must_equal BrNfe.client_wsdl_ssl_verify_mode
219
- end
220
- end
221
-
222
- describe '#client_wsdl_ssl_cert_file' do
223
- it "se eu setar um valor deve retornar esse valor" do
224
- subject.client_wsdl_ssl_cert_file = :value_client_wsdl_ssl_cert_file
225
- subject.client_wsdl_ssl_cert_file.must_equal :value_client_wsdl_ssl_cert_file
226
- end
227
- it "se não setar nenhum valor deve retornar o valor da configuração" do
228
- subject.class.new.client_wsdl_ssl_cert_file.must_equal BrNfe.client_wsdl_ssl_cert_file
229
- end
230
- end
231
-
232
- describe '#client_wsdl_ssl_cert_key_file' do
233
- it "se eu setar um valor deve retornar esse valor" do
234
- subject.client_wsdl_ssl_cert_key_file = :value_client_wsdl_ssl_cert_key_file
235
- subject.client_wsdl_ssl_cert_key_file.must_equal :value_client_wsdl_ssl_cert_key_file
236
- end
237
- it "se não setar nenhum valor deve retornar o valor da configuração" do
238
- subject.class.new.client_wsdl_ssl_cert_key_file.must_equal BrNfe.client_wsdl_ssl_cert_key_file
239
- end
240
- end
241
-
242
- describe '#client_wsdl_ssl_cert_key_password' do
243
- it "se eu setar um valor deve retornar esse valor" do
244
- subject.client_wsdl_ssl_cert_key_password = :value_client_wsdl_ssl_cert_key_password
245
- subject.client_wsdl_ssl_cert_key_password.must_equal :value_client_wsdl_ssl_cert_key_password
246
- end
247
- it "se não setar nenhum valor deve retornar o valor da configuração" do
248
- subject.class.new.client_wsdl_ssl_cert_key_password.must_equal BrNfe.client_wsdl_ssl_cert_key_password
249
- end
250
- end
251
-
252
287
  describe "#certificate_pkcs12_value" do
253
288
  it "se tiver algum valor setado deve retornar esse valor" do
254
289
  subject.certificate_pkcs12_value = "algum valor"
@@ -10,6 +10,10 @@ describe BrNfe::Endereco do
10
10
  it { must validate_presence_of(:codigo_municipio) }
11
11
  it { must validate_presence_of(:uf) }
12
12
  it { must validate_presence_of(:cep) }
13
+ it { must validate_inclusion_of(:codigo_ibge_uf).
14
+ in_array(BrNfe::Constants::CODIGO_IBGE_UF).
15
+ allow_blank
16
+ }
13
17
  end
14
18
 
15
19
  describe "#default_values" do
@@ -56,4 +60,21 @@ describe BrNfe::Endereco do
56
60
  end
57
61
  end
58
62
 
63
+ describe "#codigo_ibge_uf" do
64
+ it "se não setar nenhum valor deve pegar os primeiros 2 dígitos do código do município" do
65
+ subject.assign_attributes(codigo_ibge_uf: nil, codigo_municipio: 123456)
66
+ subject.codigo_ibge_uf.must_equal '12'
67
+ subject.assign_attributes(codigo_ibge_uf: nil, codigo_municipio: '65347')
68
+ subject.codigo_ibge_uf.must_equal '65'
69
+ end
70
+ it "se não tiver valor setado no código IBGE da cidade não da erro" do
71
+ subject.assign_attributes(codigo_ibge_uf: nil, codigo_municipio: nil)
72
+ subject.codigo_ibge_uf.must_equal ''
73
+ end
74
+ it "se setar o código ibge da uf diretamente deve desconsiderar o código do municipio" do
75
+ subject.assign_attributes(codigo_ibge_uf: '44', codigo_municipio: 123456)
76
+ subject.codigo_ibge_uf.must_equal '44'
77
+ end
78
+ end
79
+
59
80
  end
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Person do
4
+ subject { FactoryGirl.build(:person, endereco: endereco) }
5
+ let(:endereco) { FactoryGirl.build(:endereco) }
6
+
7
+ describe "validations" do
8
+ it { must validate_presence_of(:cpf_cnpj) }
9
+ it { must validate_presence_of(:razao_social) }
10
+ end
11
+
12
+ it "deve ter alias attribute com cpf, cnpj e cpf_cnpj" do
13
+ subject.cpf_cnpj = '123'
14
+ subject.cpf.must_equal '123'
15
+ subject.cnpj.must_equal '123'
16
+
17
+ subject.cnpj = '665'
18
+ subject.cpf_cnpj.must_equal '665'
19
+ subject.cpf.must_equal '665'
20
+ end
21
+
22
+ describe "#endereco" do
23
+ class OtherClassEndereco < BrNfe::ActiveModelBase
24
+ end
25
+ it "deve ter incluso o module HaveAddress" do
26
+ subject.class.included_modules.must_include BrNfe::Association::HaveAddress
27
+ end
28
+ it "o método endereco por padrão deve retornar um objeto da class BrNfe::Endereco" do
29
+ subject.endereco.must_be_kind_of BrNfe::Endereco
30
+ end
31
+ it "a classe de endereço deve derivar da configuração endereco_class" do
32
+ BrNfe.endereco_class.must_equal BrNfe::Endereco
33
+ BrNfe.endereco_class = OtherClassEndereco
34
+ subject.endereco.must_be_kind_of OtherClassEndereco
35
+
36
+ # É necessário voltar a configuração original para não falhar outros testes
37
+ BrNfe.endereco_class = BrNfe::Endereco
38
+ end
39
+ end
40
+
41
+ describe "#razao_social" do
42
+ it "deve retornar a string em maiusculoo e sem acentos" do
43
+ subject.razao_social = 'ó têxtú dève vìr SÉM ÀçÊnTÕ'
44
+ subject.razao_social.must_equal "O TEXTU DEVE VIR SEM ACENTO"
45
+ end
46
+ end
47
+
48
+ describe "#nome_fantasia" do
49
+ it "deve retornar a string em maiusculoo e sem acentos" do
50
+ subject.nome_fantasia = 'ó têxtú dève vìr SÉM ÀçÊnTÕ'
51
+ subject.nome_fantasia.must_equal "O TEXTU DEVE VIR SEM ACENTO"
52
+ end
53
+ end
54
+
55
+ end
@@ -0,0 +1,150 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Product::Base do
4
+ subject { FactoryGirl.build(:product_base) }
5
+
6
+ describe "Validations" do
7
+ it do
8
+ subject.certificate_pkcs12_path = nil
9
+ must validate_presence_of(:certificate)
10
+ end
11
+ end
12
+
13
+ it '#ssl_request? deve ser true' do
14
+ subject.ssl_request?.must_equal true
15
+ end
16
+
17
+ describe '#gateway' do
18
+ context "Estados que usam o servidor SVRS" do
19
+ let(:env) { SecureRandom.hex(5) }
20
+ it 'AC 12 - Acre' do
21
+ subject.assign_attributes ibge_code_of_issuer_uf: '12', env: env
22
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVRS
23
+ subject.gateway.env.must_equal env
24
+ end
25
+
26
+ it 'AL 27 - Alagoas' do
27
+ subject.assign_attributes ibge_code_of_issuer_uf: '27', env: env
28
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVRS
29
+ subject.gateway.env.must_equal env
30
+ end
31
+
32
+ it 'AP 16 - Amapá ' do
33
+ subject.assign_attributes ibge_code_of_issuer_uf: '16', env: env
34
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVRS
35
+ subject.gateway.env.must_equal env
36
+ end
37
+
38
+ it 'DF 53 - Distrito Federal' do
39
+ subject.assign_attributes ibge_code_of_issuer_uf: '53', env: env
40
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVRS
41
+ subject.gateway.env.must_equal env
42
+ end
43
+
44
+ it 'ES 32 - Espírito Santo' do
45
+ subject.assign_attributes ibge_code_of_issuer_uf: '32', env: env
46
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVRS
47
+ subject.gateway.env.must_equal env
48
+ end
49
+
50
+ it 'PB 25 - Paraíba' do
51
+ subject.assign_attributes ibge_code_of_issuer_uf: '25', env: env
52
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVRS
53
+ subject.gateway.env.must_equal env
54
+ end
55
+
56
+ it 'RJ 33 - Rio de Janeiro' do
57
+ subject.assign_attributes ibge_code_of_issuer_uf: '33', env: env
58
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVRS
59
+ subject.gateway.env.must_equal env
60
+ end
61
+
62
+ it 'RN 24 - Rio Grande do Norte' do
63
+ subject.assign_attributes ibge_code_of_issuer_uf: '24', env: env
64
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVRS
65
+ subject.gateway.env.must_equal env
66
+ end
67
+
68
+ it 'RN 43 - Rio Grande do Sul' do
69
+ subject.assign_attributes ibge_code_of_issuer_uf: '43', env: env
70
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVRS
71
+ subject.gateway.env.must_equal env
72
+ end
73
+
74
+ it 'RO 11 - Rondônia' do
75
+ subject.assign_attributes ibge_code_of_issuer_uf: '11', env: env
76
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVRS
77
+ subject.gateway.env.must_equal env
78
+ end
79
+
80
+ it 'RR 14 - Roraima' do
81
+ subject.assign_attributes ibge_code_of_issuer_uf: '14', env: env
82
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVRS
83
+ subject.gateway.env.must_equal env
84
+ end
85
+
86
+ it 'SC 42 - Santa Catarina' do
87
+ subject.assign_attributes ibge_code_of_issuer_uf: '42', env: env
88
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVRS
89
+ subject.gateway.env.must_equal env
90
+ end
91
+
92
+ it 'SE 28 - Sergipe' do
93
+ subject.assign_attributes ibge_code_of_issuer_uf: '28', env: env
94
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVRS
95
+ subject.gateway.env.must_equal env
96
+ end
97
+
98
+ it 'TO 17 - Tocantins' do
99
+ subject.assign_attributes ibge_code_of_issuer_uf: '17', env: env
100
+ subject.gateway.must_be_kind_of BrNfe::Product::Gateway::WebServiceSVRS
101
+ subject.gateway.env.must_equal env
102
+ end
103
+ end
104
+ end
105
+
106
+ describe 'Métodos que devem ser sobrescritos' do
107
+ it '#url_xmlns' do
108
+ assert_raises RuntimeError do
109
+ subject.url_xmlns
110
+ end
111
+ end
112
+ it '#gateway_xml_version' do
113
+ assert_raises RuntimeError do
114
+ subject.gateway_xml_version
115
+ end
116
+ end
117
+ end
118
+
119
+ describe '#xml_version - deve converter a versão em valor usável no XML' do
120
+ it "Para versão :v3_10" do
121
+ subject.stubs(:gateway_xml_version).returns(:v3_10)
122
+ subject.xml_version.must_equal '3.10'
123
+ end
124
+ it "Para versão :v2_00" do
125
+ subject.stubs(:gateway_xml_version).returns(:v2_00)
126
+ subject.xml_version.must_equal '2.00'
127
+ end
128
+ end
129
+
130
+ describe "#emitente" do
131
+ class OtherClassEmitente < BrNfe::ActiveModelBase
132
+ end
133
+ it "deve ter incluso o module HaveEmitente" do
134
+ subject.class.included_modules.must_include BrNfe::Association::HaveEmitente
135
+ end
136
+ it "o método #emitente_class deve ter por padrão a class BrNfe::Product::Emitente" do
137
+ subject.emitente.must_be_kind_of BrNfe::Product::Emitente
138
+ subject.send(:emitente_class).must_equal BrNfe::Product::Emitente
139
+ end
140
+ it "a class do emitente pode ser modificada através da configuração emitente_product_class" do
141
+ BrNfe.emitente_product_class = OtherClassEmitente
142
+ subject.emitente.must_be_kind_of OtherClassEmitente
143
+ subject.send(:emitente_class).must_equal OtherClassEmitente
144
+
145
+ # É necessário voltar a configuração original para não falhar outros testes
146
+ BrNfe.emitente_product_class = BrNfe::Product::Emitente
147
+ end
148
+ end
149
+
150
+ end
@@ -0,0 +1,59 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Product::ConsultaStatusServico do
4
+ subject { FactoryGirl.build(:product_consulta_status_servico) }
5
+ let(:gateway) { FactoryGirl.build(:product_gateway_web_service_svrs) }
6
+
7
+ before do
8
+ subject.stubs(:gateway).returns(gateway)
9
+ end
10
+
11
+ it 'o método #url_xmlns deve pegar o valor do método url_xmlns_status_servico do gateway ' do
12
+ gateway.expects(:url_xmlns_status_servico).returns('http://teste.url_xmlns_status_servico.com')
13
+ subject.url_xmlns.must_equal 'http://teste.url_xmlns_status_servico.com'
14
+ end
15
+
16
+ it 'o método #wsdl deve pegar o valor do método wsdl_status_servico do gateway ' do
17
+ gateway.expects(:wsdl_status_servico).returns('http://teste.wsdl_status_servico.com')
18
+ subject.wsdl.must_equal 'http://teste.wsdl_status_servico.com'
19
+ end
20
+
21
+ it 'o método #method_wsdl deve pegar o valor do método operation_status_servico do gateway ' do
22
+ gateway.expects(:operation_status_servico).returns(:operation_status_servico)
23
+ subject.method_wsdl.must_equal :operation_status_servico
24
+ end
25
+
26
+ it 'o método #gateway_xml_version deve pegar o valor do método version_xml_status_servico do gateway ' do
27
+ gateway.expects(:version_xml_status_servico).returns(:v3_20)
28
+ subject.gateway_xml_version.must_equal :v3_20
29
+ end
30
+
31
+ describe '#xml_builder' do
32
+ it "deve renderizar para o xml consulta_status_servico" do
33
+ subject.expects(:render_xml).with('consulta_status_servico').returns('<ok>1</ok>')
34
+ subject.xml_builder.must_equal '<ok>1</ok>'
35
+ end
36
+ end
37
+
38
+ describe "Validação do XML através do XSD" do
39
+ let(:schemas_dir) { BrNfe.root+'/lib/br_nfe/product/xml/v3_10/XSD' }
40
+ def validate_schema
41
+ subject.stubs(:certificate).returns(nil)
42
+ Dir.chdir(schemas_dir) do
43
+ schema = Nokogiri::XML::Schema(IO.read('consStatServ_v3.10.xsd'))
44
+ document = Nokogiri::XML(subject.xml_builder)
45
+ errors = schema.validate(document)
46
+ errors.must_be_empty
47
+ end
48
+ end
49
+ it "Deve ser válido em ambiente de produção" do
50
+ subject.env = :production
51
+ validate_schema
52
+ end
53
+ it "Deve ser válido em ambiente de homologação" do
54
+ subject.env = :test
55
+ validate_schema
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Product::Emitente do
4
+ subject { FactoryGirl.build(:product_emitente, endereco: endereco) }
5
+ let(:endereco) { FactoryGirl.build(:endereco) }
6
+
7
+ it "deve herdar da classe ::Person" do
8
+ subject.must_be_kind_of BrNfe::Product::Emitente
9
+ subject.must_be_kind_of BrNfe::Person
10
+ end
11
+
12
+ describe "validations" do
13
+ it { must validate_presence_of(:inscricao_municipal) }
14
+ it { must validate_presence_of(:natureza_operacao) }
15
+ describe "valida o endereco" do
16
+ it "deve ser inválido se endereco for invalido" do
17
+ subject.endereco.stubs(:valid?).returns(false)
18
+ subject.endereco.stubs(:errors).returns(stub(full_messages: ["Erro 1"] ))
19
+ subject.valid?.must_equal false
20
+ subject.errors.full_messages.include?("Endereço: Erro 1").must_equal true
21
+ end
22
+ it "deve ser válido se endereco for valido" do
23
+ subject.endereco.stubs(:valid?).returns(true)
24
+ subject.valid?.must_equal true
25
+ end
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Product::Gateway::Base do
4
+ subject { FactoryGirl.build(:product_gateway_base) }
5
+
6
+ describe '#env_production?' do
7
+ it "se env for igual a :production deve ser true" do
8
+ subject.env = :production
9
+ subject.env_production?.must_equal true
10
+ end
11
+ it "deve ser false se env for diferente a :production" do
12
+ subject.env = :test
13
+ subject.env_production?.must_equal false
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+
3
+ describe BrNfe::Product::Gateway::WebServiceSVRS do
4
+ subject { FactoryGirl.build(:product_gateway_web_service_svrs) }
5
+
6
+ it "deve herdar da class base" do
7
+ subject.class.superclass.must_equal BrNfe::Product::Gateway::Base
8
+ end
9
+
10
+ describe 'STATUS SERVIÇO' do
11
+ describe '#wsdl_status_servico' do
12
+ it "para ambiente de produção" do
13
+ subject.env = :production
14
+ subject.wsdl_status_servico.must_equal 'https://nfe.sefazrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico2.asmx?wsdl'
15
+ end
16
+ it "para ambiente de homologação" do
17
+ subject.env = :test
18
+ subject.wsdl_status_servico.must_equal 'https://nfe-homologacao.svrs.rs.gov.br/ws/NfeStatusServico/NfeStatusServico2.asmx?wsdl'
19
+ end
20
+ end
21
+
22
+ describe '#operation_status_servico' do
23
+ it { subject.operation_status_servico.must_equal :nfe_status_servico_nf2 }
24
+ end
25
+
26
+ describe '#version_xml_status_servico' do
27
+ it { subject.version_xml_status_servico.must_equal :v3_10 }
28
+ end
29
+
30
+ describe '#url_xmlns_status_servico' do
31
+ it { subject.url_xmlns_status_servico.must_equal 'http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2' }
32
+ end
33
+ end
34
+
35
+
36
+ end
@@ -0,0 +1,80 @@
1
+ require 'test_helper'
2
+
3
+ class HaveIntermediarioTest < BrNfe::ActiveModelBase
4
+ include BrNfe::Service::Association::HaveIntermediario
5
+ end
6
+ class NewClassIntermediario < BrNfe::Person
7
+ end
8
+
9
+ describe HaveIntermediarioTest do
10
+ subject { HaveIntermediarioTest.new(intermediario: intermediario) }
11
+ let(:intermediario) { BrNfe::Intermediario.new }
12
+
13
+ it 'deve_iniciar_o_intermediario_com_nil' do
14
+ subject.class.new.intermediario.must_be_nil
15
+ end
16
+
17
+ it 'se_tiver_intermediario_posso_setalo_como_nil' do
18
+ subject.intermediario.wont_be_nil
19
+ subject.intermediario = nil
20
+ subject.intermediario.must_be_nil
21
+ end
22
+
23
+ it 'deve_manter_o_objeto_intermediario_se_ja_tiver' do
24
+ subject.intermediario.must_equal intermediario
25
+ intermediario.cpf_cnpj = 'nova-www'
26
+ subject.intermediario.cpf_cnpj.must_equal 'nova-www'
27
+ end
28
+
29
+ it 'Se_setar_o_intermediario_com_outra_class_deve_ignorar' do
30
+ subject.intermediario = 7777
31
+ subject.intermediario.must_equal intermediario
32
+ end
33
+
34
+ it 'posso_setar_o_intermediario_com_um_hash_com_os_parametros_do_intermediario' do
35
+ intermediario.assign_attributes(cpf_cnpj: '123456', razao_social: '123465')
36
+ subject.intermediario = {cpf_cnpj: '99999', razao_social: '654389'}
37
+ subject.intermediario.cpf_cnpj.must_equal '99999'
38
+ subject.intermediario.razao_social.must_equal '654389'
39
+ end
40
+
41
+ it 'ao_setar_um_intermediario_com_um_hash_e_nao_tiver_um_intermediario_deve_instanciar_um_com_os_parametros' do
42
+ subject.intermediario = nil
43
+ subject.intermediario = {cpf_cnpj: '99999', razao_social: '654389'}
44
+ subject.intermediario.cpf_cnpj.must_equal '99999'
45
+ subject.intermediario.razao_social.must_equal '654389'
46
+ end
47
+
48
+ it 'posso_setar_o_intermediario_com_um_bloco' do
49
+ intermediario.assign_attributes(cpf_cnpj: '123456', razao_social: '11111')
50
+ subject.intermediario do |address|
51
+ address.cpf_cnpj = '99999'
52
+ address.razao_social = '11111'
53
+ end
54
+ subject.intermediario.cpf_cnpj.must_equal '99999'
55
+ subject.intermediario.razao_social.must_equal '11111'
56
+ end
57
+
58
+ it 'ao_setar_um_intermediario_com_um_bloco_e_nao_tiver_um_intermediario_deve_instanciar_um_com_os_parametros' do
59
+ subject.intermediario = nil
60
+ subject.intermediario do |address|
61
+ address.cpf_cnpj = '99999'
62
+ address.razao_social = '11111'
63
+ end
64
+ subject.intermediario.cpf_cnpj.must_equal '99999'
65
+ subject.intermediario.razao_social.must_equal '11111'
66
+ end
67
+
68
+ it 'posso_mudar_o_objeto_intermediario' do
69
+ novo_intermediario = FactoryGirl.build(:intermediario)
70
+ subject.intermediario = novo_intermediario
71
+ subject.intermediario.must_equal novo_intermediario
72
+ end
73
+
74
+ it 'posso_modificar_a_class_do_intermediario' do
75
+ BrNfe.intermediario_service_class = NewClassIntermediario
76
+ novo_objeto = subject.class.new(intermediario: {cpf_cnpj: '123'})
77
+ novo_objeto.intermediario.class.must_equal NewClassIntermediario
78
+ BrNfe.intermediario_service_class = BrNfe::Service::Intermediario
79
+ end
80
+ end