document_number 0.9.6 → 0.10.0

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: 35fae6ae1f0b9e7ab3c192d566abebf8e8c15802
4
- data.tar.gz: 4d314ff8ae3ed1ad588d931b377e062bb1fa3419
3
+ metadata.gz: 473926450942cfd2c9845b29c5262ed2a1c743dc
4
+ data.tar.gz: fe5b8b732069c71dc40028e97861006f4bee475a
5
5
  SHA512:
6
- metadata.gz: 37ecd7f26c7186b10ddefccd479e997642de650239bad207bea9ff650db70ab7d992d8cde4009fca9d72337d4a395b220afa3a3df6e95ad39b173c036af23a6d
7
- data.tar.gz: fb96625b109d6f08331335b09e257efc2924bab08f5194acda212adc3121ee66252d26dbde13884cf06b25a7b0d42e47bc426b86c7e51c4510efedc41c691bfb
6
+ metadata.gz: 82c6a5629bc1d51abaf59123c117e5f5f082e55a59882b24944b9e9c03fdbc4f193391bfa21d82d9e29f62aa6b62fd69cf868cf3520f164f54fe2acfc2a81de3
7
+ data.tar.gz: 7d42da11a847e0c0b100543fefb0d8f244f7ca402200f1385ad458c46d1892cdc95e84e0ad12588a64730b4bca769421ef98aebceb76da2510b457d4c427967c
@@ -28,7 +28,7 @@ module DocumentNumber
28
28
 
29
29
  method_name = "auto_increment_#{options[:column]}"
30
30
 
31
- before_create method_name
31
+ before_validation method_name
32
32
  after_initialize method_name, :if => Proc.new { with_number == true }
33
33
 
34
34
  define_method method_name do
@@ -50,6 +50,13 @@ module DocumentNumber
50
50
  rescue
51
51
  []
52
52
  end
53
+
54
+ def update_document_number(number)
55
+ document = self.to_s.underscore
56
+ doc_in_db = DocumentNumber.where(:document => document).last
57
+ return false if doc_in_db && doc_in_db.number.to_i > number.to_i
58
+ doc_in_db.update_attribute(:number, number)
59
+ end
53
60
  end
54
61
  end
55
62
  end
@@ -1,3 +1,3 @@
1
1
  module DocumentNumber
2
- VERSION = '0.9.6'
2
+ VERSION = '0.10.0'
3
3
  end
@@ -0,0 +1,6 @@
1
+ class SupplierComplaint < ActiveRecord::Base
2
+ has_document_number start: 500
3
+
4
+ validates :text, presence: true
5
+ validates :number, presence: true
6
+ end
@@ -0,0 +1,10 @@
1
+ class SupplierComplaints < ActiveRecord::Migration
2
+ def change
3
+ create_table :supplier_complaints do |t|
4
+ t.string :number
5
+ t.string :text
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -11,32 +11,39 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20140610093243) do
14
+ ActiveRecord::Schema.define(version: 20150617152432) do
15
15
 
16
- create_table "document_numbers", force: true do |t|
16
+ create_table "document_numbers", force: :cascade do |t|
17
17
  t.string "document"
18
- t.integer "number", null: false, default: 1
18
+ t.integer "number", default: 1, null: false
19
19
  t.datetime "created_at"
20
20
  end
21
21
 
22
22
  add_index "document_numbers", ["document"], name: "index_document_numbers_on_document", unique: true
23
23
 
24
- create_table "inventories", force: true do |t|
24
+ create_table "inventories", force: :cascade do |t|
25
25
  t.string "number"
26
26
  t.datetime "created_at"
27
27
  t.datetime "updated_at"
28
28
  end
29
29
 
30
- create_table "invoices", force: true do |t|
30
+ create_table "invoices", force: :cascade do |t|
31
31
  t.string "number"
32
32
  t.datetime "created_at"
33
33
  t.datetime "updated_at"
34
34
  end
35
35
 
36
- create_table "price_adjustments", force: true do |t|
36
+ create_table "price_adjustments", force: :cascade do |t|
37
37
  t.string "document_number"
38
38
  t.datetime "created_at"
39
39
  t.datetime "updated_at"
40
40
  end
41
41
 
42
+ create_table "supplier_complaints", force: :cascade do |t|
43
+ t.string "number"
44
+ t.string "text"
45
+ t.datetime "created_at"
46
+ t.datetime "updated_at"
47
+ end
48
+
42
49
  end
Binary file
@@ -1625,3 +1625,402 @@
1625
1625
  SQL (0.1ms) INSERT INTO "inventories" ("created_at", "number", "updated_at") VALUES (?, ?, ?) [["created_at", "2014-07-18 19:45:49.671615"], ["number", "1"], ["updated_at", "2014-07-18 19:45:49.671615"]]
1626
1626
   (0.1ms) RELEASE SAVEPOINT active_record_1
1627
1627
   (0.4ms) rollback transaction
1628
+  (0.3ms) begin transaction
1629
+  (0.0ms) SAVEPOINT active_record_1
1630
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'invoice' LIMIT 1
1631
+ SQL (0.7ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.682368"], ["document", "invoice"], ["number", 2]]
1632
+  (0.1ms) RELEASE SAVEPOINT active_record_1
1633
+  (0.0ms) SAVEPOINT active_record_1
1634
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'invoice' LIMIT 1
1635
+ SQL (1.0ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 3]]
1636
+  (0.1ms) RELEASE SAVEPOINT active_record_1
1637
+  (0.0ms) SAVEPOINT active_record_1
1638
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'invoice' LIMIT 1
1639
+ SQL (0.0ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 4]]
1640
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1641
+  (0.9ms) rollback transaction
1642
+  (0.1ms) begin transaction
1643
+  (0.0ms) SAVEPOINT active_record_1
1644
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'invoice' LIMIT 1
1645
+ SQL (0.2ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.695937"], ["document", "invoice"], ["number", 2]]
1646
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1647
+  (0.4ms) rollback transaction
1648
+  (0.0ms) begin transaction
1649
+  (0.0ms) rollback transaction
1650
+  (0.0ms) begin transaction
1651
+  (0.0ms) SAVEPOINT active_record_1
1652
+  (0.0ms) SAVEPOINT active_record_2
1653
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'invoice' LIMIT 1
1654
+ SQL (0.2ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.699772"], ["document", "invoice"], ["number", 2]]
1655
+  (0.0ms) RELEASE SAVEPOINT active_record_2
1656
+ SQL (0.1ms) INSERT INTO "invoices" ("created_at", "number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.698763"], ["number", "invoice/1"], ["updated_at", "2015-07-06 13:21:07.698763"]]
1657
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1658
+  (0.4ms) rollback transaction
1659
+  (0.1ms) begin transaction
1660
+  (0.0ms) SAVEPOINT active_record_1
1661
+  (0.1ms) SAVEPOINT active_record_2
1662
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1663
+ SQL (0.3ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.706180"], ["document", "price_adjustment"], ["number", 501]]
1664
+  (0.0ms) RELEASE SAVEPOINT active_record_2
1665
+ SQL (0.1ms) INSERT INTO "price_adjustments" ("created_at", "document_number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.703308"], ["document_number", "500"], ["updated_at", "2015-07-06 13:21:07.703308"]]
1666
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1667
+  (0.4ms) rollback transaction
1668
+  (0.1ms) begin transaction
1669
+  (0.0ms) SAVEPOINT active_record_1
1670
+  (0.0ms) SAVEPOINT active_record_2
1671
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1672
+ SQL (0.3ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.710018"], ["document", "price_adjustment"], ["number", 501]]
1673
+  (0.0ms) RELEASE SAVEPOINT active_record_2
1674
+ SQL (0.1ms) INSERT INTO "price_adjustments" ("created_at", "document_number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.709096"], ["document_number", "500"], ["updated_at", "2015-07-06 13:21:07.709096"]]
1675
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1676
+  (0.0ms) SAVEPOINT active_record_1
1677
+  (0.0ms) SAVEPOINT active_record_2
1678
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1679
+ SQL (0.2ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 502]]
1680
+  (0.0ms) RELEASE SAVEPOINT active_record_2
1681
+ SQL (0.1ms) INSERT INTO "price_adjustments" ("created_at", "document_number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.711468"], ["document_number", "501"], ["updated_at", "2015-07-06 13:21:07.711468"]]
1682
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1683
+  (0.6ms) rollback transaction
1684
+  (0.1ms) begin transaction
1685
+  (0.0ms) SAVEPOINT active_record_1
1686
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1687
+ SQL (0.3ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.715129"], ["document", "price_adjustment"], ["number", 501]]
1688
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1689
+  (0.0ms) SAVEPOINT active_record_1
1690
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1691
+ SQL (0.2ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 502]]
1692
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1693
+  (0.0ms) SAVEPOINT active_record_1
1694
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1695
+ SQL (0.0ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 503]]
1696
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1697
+  (0.6ms) rollback transaction
1698
+  (0.1ms) begin transaction
1699
+  (0.1ms) rollback transaction
1700
+  (0.0ms) begin transaction
1701
+  (0.0ms) SAVEPOINT active_record_1
1702
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1703
+ SQL (0.2ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.721198"], ["document", "price_adjustment"], ["number", 501]]
1704
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1705
+  (0.4ms) rollback transaction
1706
+  (0.0ms) begin transaction
1707
+  (0.0ms) SAVEPOINT active_record_1
1708
+  (0.0ms) SAVEPOINT active_record_2
1709
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1710
+ SQL (0.3ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.724190"], ["document", "price_adjustment"], ["number", 501]]
1711
+  (0.0ms) RELEASE SAVEPOINT active_record_2
1712
+ SQL (0.1ms) INSERT INTO "price_adjustments" ("created_at", "document_number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.723242"], ["document_number", "500"], ["updated_at", "2015-07-06 13:21:07.723242"]]
1713
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1714
+  (0.4ms) rollback transaction
1715
+  (0.0ms) begin transaction
1716
+  (0.0ms) SAVEPOINT active_record_1
1717
+  (0.1ms) SAVEPOINT active_record_2
1718
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1719
+ SQL (0.3ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.730544"], ["document", "inventory"], ["number", 2]]
1720
+  (0.1ms) RELEASE SAVEPOINT active_record_2
1721
+ SQL (0.1ms) INSERT INTO "inventories" ("created_at", "number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.727928"], ["number", "1"], ["updated_at", "2015-07-06 13:21:07.727928"]]
1722
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1723
+  (0.0ms) SAVEPOINT active_record_1
1724
+  (0.0ms) SAVEPOINT active_record_2
1725
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1726
+ SQL (0.2ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 3]]
1727
+  (0.0ms) RELEASE SAVEPOINT active_record_2
1728
+ SQL (0.1ms) INSERT INTO "inventories" ("created_at", "number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.732235"], ["number", "2"], ["updated_at", "2015-07-06 13:21:07.732235"]]
1729
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1730
+  (0.6ms) rollback transaction
1731
+  (0.0ms) begin transaction
1732
+  (0.0ms) SAVEPOINT active_record_1
1733
+ SQL (0.3ms) INSERT INTO "inventories" ("created_at", "number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.735537"], ["number", "500"], ["updated_at", "2015-07-06 13:21:07.735537"]]
1734
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1735
+  (0.4ms) rollback transaction
1736
+  (0.0ms) begin transaction
1737
+  (0.1ms) SAVEPOINT active_record_1
1738
+ SQL (0.4ms) INSERT INTO "inventories" ("created_at", "number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.737932"], ["number", "5"], ["updated_at", "2015-07-06 13:21:07.737932"]]
1739
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1740
+  (0.0ms) SAVEPOINT active_record_1
1741
+ SQL (0.3ms) UPDATE "inventories" SET "updated_at" = '2015-07-06 13:21:07.739560' WHERE "inventories"."id" = 1
1742
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1743
+  (0.6ms) rollback transaction
1744
+  (0.0ms) begin transaction
1745
+  (0.1ms) SAVEPOINT active_record_1
1746
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1747
+ SQL (0.2ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.742789"], ["document", "inventory"], ["number", 2]]
1748
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1749
+  (0.3ms) rollback transaction
1750
+  (0.0ms) begin transaction
1751
+  (0.0ms) rollback transaction
1752
+  (0.0ms) begin transaction
1753
+  (0.0ms) SAVEPOINT active_record_1
1754
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1755
+ SQL (0.3ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.745852"], ["document", "inventory"], ["number", 2]]
1756
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1757
+  (0.0ms) SAVEPOINT active_record_1
1758
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1759
+ SQL (0.2ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 3]]
1760
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1761
+  (0.0ms) SAVEPOINT active_record_1
1762
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1763
+ SQL (0.0ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 4]]
1764
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1765
+  (0.6ms) rollback transaction
1766
+  (0.0ms) begin transaction
1767
+  (0.0ms) SAVEPOINT active_record_1
1768
+  (0.0ms) SAVEPOINT active_record_2
1769
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1770
+ SQL (0.2ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.750944"], ["document", "inventory"], ["number", 2]]
1771
+  (0.0ms) RELEASE SAVEPOINT active_record_2
1772
+ SQL (0.1ms) INSERT INTO "inventories" ("created_at", "number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 13:21:07.750048"], ["number", "1"], ["updated_at", "2015-07-06 13:21:07.750048"]]
1773
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1774
+  (0.3ms) rollback transaction
1775
+  (0.3ms) begin transaction
1776
+  (0.0ms) SAVEPOINT active_record_1
1777
+  (0.1ms) SAVEPOINT active_record_2
1778
+ DocumentNumber::DocumentNumber Load (0.4ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1779
+ SQL (0.9ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.457603"], ["document", "price_adjustment"], ["number", 501]]
1780
+  (0.1ms) RELEASE SAVEPOINT active_record_2
1781
+ SQL (0.5ms) INSERT INTO "price_adjustments" ("created_at", "document_number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.444371"], ["document_number", "500"], ["updated_at", "2015-07-06 15:20:04.444371"]]
1782
+  (0.1ms) RELEASE SAVEPOINT active_record_1
1783
+  (0.4ms) rollback transaction
1784
+  (0.1ms) begin transaction
1785
+  (0.1ms) SAVEPOINT active_record_1
1786
+  (0.0ms) SAVEPOINT active_record_2
1787
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1788
+ SQL (0.3ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.466831"], ["document", "price_adjustment"], ["number", 501]]
1789
+  (0.0ms) RELEASE SAVEPOINT active_record_2
1790
+ SQL (0.1ms) INSERT INTO "price_adjustments" ("created_at", "document_number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.465565"], ["document_number", "500"], ["updated_at", "2015-07-06 15:20:04.465565"]]
1791
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1792
+  (0.0ms) SAVEPOINT active_record_1
1793
+  (0.0ms) SAVEPOINT active_record_2
1794
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1795
+ SQL (1.2ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 502]]
1796
+  (0.1ms) RELEASE SAVEPOINT active_record_2
1797
+ SQL (0.1ms) INSERT INTO "price_adjustments" ("created_at", "document_number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.468714"], ["document_number", "501"], ["updated_at", "2015-07-06 15:20:04.468714"]]
1798
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1799
+  (0.6ms) rollback transaction
1800
+  (0.0ms) begin transaction
1801
+  (0.0ms) SAVEPOINT active_record_1
1802
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1803
+ SQL (0.3ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.474890"], ["document", "price_adjustment"], ["number", 501]]
1804
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1805
+  (0.0ms) SAVEPOINT active_record_1
1806
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1807
+ SQL (0.2ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 502]]
1808
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1809
+  (0.0ms) SAVEPOINT active_record_1
1810
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1811
+ SQL (0.0ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 503]]
1812
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1813
+  (0.6ms) rollback transaction
1814
+  (0.0ms) begin transaction
1815
+  (0.0ms) SAVEPOINT active_record_1
1816
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1817
+ SQL (0.2ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.480110"], ["document", "price_adjustment"], ["number", 501]]
1818
+  (0.1ms) RELEASE SAVEPOINT active_record_1
1819
+  (0.4ms) rollback transaction
1820
+  (0.1ms) begin transaction
1821
+  (0.1ms) rollback transaction
1822
+  (0.1ms) begin transaction
1823
+  (0.0ms) SAVEPOINT active_record_1
1824
+  (0.0ms) SAVEPOINT active_record_2
1825
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1826
+ SQL (0.3ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.484466"], ["document", "price_adjustment"], ["number", 501]]
1827
+  (0.1ms) RELEASE SAVEPOINT active_record_2
1828
+ SQL (0.1ms) INSERT INTO "price_adjustments" ("created_at", "document_number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.483442"], ["document_number", "500"], ["updated_at", "2015-07-06 15:20:04.483442"]]
1829
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1830
+  (0.4ms) rollback transaction
1831
+  (0.0ms) begin transaction
1832
+  (0.0ms) SAVEPOINT active_record_1
1833
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'invoice' LIMIT 1
1834
+ SQL (0.2ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.490078"], ["document", "invoice"], ["number", 2]]
1835
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1836
+  (0.4ms) rollback transaction
1837
+  (0.1ms) begin transaction
1838
+  (0.0ms) rollback transaction
1839
+  (0.0ms) begin transaction
1840
+  (0.0ms) SAVEPOINT active_record_1
1841
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'invoice' LIMIT 1
1842
+ SQL (0.3ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.493822"], ["document", "invoice"], ["number", 2]]
1843
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1844
+  (0.0ms) SAVEPOINT active_record_1
1845
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'invoice' LIMIT 1
1846
+ SQL (0.2ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 3]]
1847
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1848
+  (0.0ms) SAVEPOINT active_record_1
1849
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'invoice' LIMIT 1
1850
+ SQL (0.0ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 4]]
1851
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1852
+  (0.6ms) rollback transaction
1853
+  (0.0ms) begin transaction
1854
+  (0.0ms) SAVEPOINT active_record_1
1855
+  (0.0ms) SAVEPOINT active_record_2
1856
+ DocumentNumber::DocumentNumber Load (0.2ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'invoice' LIMIT 1
1857
+ SQL (0.4ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.500002"], ["document", "invoice"], ["number", 2]]
1858
+  (0.1ms) RELEASE SAVEPOINT active_record_2
1859
+ SQL (0.5ms) INSERT INTO "invoices" ("created_at", "number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.498455"], ["number", "invoice/1"], ["updated_at", "2015-07-06 15:20:04.498455"]]
1860
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1861
+  (0.4ms) rollback transaction
1862
+  (0.0ms) begin transaction
1863
+  (0.1ms) SAVEPOINT active_record_1
1864
+ SQL (0.6ms) INSERT INTO "inventories" ("created_at", "number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.507219"], ["number", "500"], ["updated_at", "2015-07-06 15:20:04.507219"]]
1865
+  (0.1ms) RELEASE SAVEPOINT active_record_1
1866
+  (0.4ms) rollback transaction
1867
+  (0.0ms) begin transaction
1868
+  (0.0ms) SAVEPOINT active_record_1
1869
+ SQL (0.2ms) INSERT INTO "inventories" ("created_at", "number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.510145"], ["number", "5"], ["updated_at", "2015-07-06 15:20:04.510145"]]
1870
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1871
+  (0.0ms) SAVEPOINT active_record_1
1872
+ SQL (0.2ms) UPDATE "inventories" SET "updated_at" = '2015-07-06 15:20:04.511136' WHERE "inventories"."id" = 1
1873
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1874
+  (0.6ms) rollback transaction
1875
+  (0.0ms) begin transaction
1876
+  (0.0ms) SAVEPOINT active_record_1
1877
+  (0.0ms) SAVEPOINT active_record_2
1878
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1879
+ SQL (0.3ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.514120"], ["document", "inventory"], ["number", 2]]
1880
+  (0.0ms) RELEASE SAVEPOINT active_record_2
1881
+ SQL (0.1ms) INSERT INTO "inventories" ("created_at", "number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.513150"], ["number", "1"], ["updated_at", "2015-07-06 15:20:04.513150"]]
1882
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1883
+  (0.0ms) SAVEPOINT active_record_1
1884
+  (0.0ms) SAVEPOINT active_record_2
1885
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1886
+ SQL (0.5ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 3]]
1887
+  (0.1ms) RELEASE SAVEPOINT active_record_2
1888
+ SQL (0.1ms) INSERT INTO "inventories" ("created_at", "number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.515919"], ["number", "2"], ["updated_at", "2015-07-06 15:20:04.515919"]]
1889
+  (0.1ms) RELEASE SAVEPOINT active_record_1
1890
+  (0.5ms) rollback transaction
1891
+  (0.0ms) begin transaction
1892
+  (0.0ms) SAVEPOINT active_record_1
1893
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1894
+ SQL (0.3ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.521427"], ["document", "inventory"], ["number", 2]]
1895
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1896
+  (0.0ms) SAVEPOINT active_record_1
1897
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1898
+ SQL (0.2ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 3]]
1899
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1900
+  (0.0ms) SAVEPOINT active_record_1
1901
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1902
+ SQL (0.0ms) UPDATE "document_numbers" SET "number" = ? WHERE "document_numbers"."id" = 1 [["number", 4]]
1903
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1904
+  (0.8ms) rollback transaction
1905
+  (0.0ms) begin transaction
1906
+  (0.0ms) rollback transaction
1907
+  (0.0ms) begin transaction
1908
+  (0.0ms) SAVEPOINT active_record_1
1909
+ DocumentNumber::DocumentNumber Load (0.1ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1910
+ SQL (0.3ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.527663"], ["document", "inventory"], ["number", 2]]
1911
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1912
+  (0.4ms) rollback transaction
1913
+  (0.0ms) begin transaction
1914
+  (0.0ms) SAVEPOINT active_record_1
1915
+  (0.1ms) SAVEPOINT active_record_2
1916
+ DocumentNumber::DocumentNumber Load (0.2ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1917
+ SQL (0.3ms) INSERT INTO "document_numbers" ("created_at", "document", "number") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.531303"], ["document", "inventory"], ["number", 2]]
1918
+  (0.1ms) RELEASE SAVEPOINT active_record_2
1919
+ SQL (0.1ms) INSERT INTO "inventories" ("created_at", "number", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-07-06 15:20:04.529753"], ["number", "1"], ["updated_at", "2015-07-06 15:20:04.529753"]]
1920
+  (0.0ms) RELEASE SAVEPOINT active_record_1
1921
+  (0.4ms) rollback transaction
1922
+  (0.2ms) begin transaction
1923
+  (0.0ms) SAVEPOINT active_record_1
1924
+ DocumentNumber::DocumentNumber Load (0.2ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'invoice' LIMIT 1
1925
+ SQLite3::SQLException: no such table: document_numbers: SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'invoice' LIMIT 1
1926
+  (0.0ms) ROLLBACK TO SAVEPOINT active_record_1
1927
+  (0.1ms) rollback transaction
1928
+  (0.0ms) begin transaction
1929
+  (0.0ms) rollback transaction
1930
+  (0.1ms) begin transaction
1931
+  (0.0ms) rollback transaction
1932
+  (0.0ms) begin transaction
1933
+  (0.0ms) rollback transaction
1934
+  (0.0ms) begin transaction
1935
+  (0.0ms) SAVEPOINT active_record_1
1936
+ DocumentNumber::DocumentNumber Load (0.2ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1937
+ SQLite3::SQLException: no such table: document_numbers: SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1938
+  (0.0ms) ROLLBACK TO SAVEPOINT active_record_1
1939
+  (0.1ms) rollback transaction
1940
+  (0.0ms) begin transaction
1941
+  (0.0ms) rollback transaction
1942
+  (0.0ms) begin transaction
1943
+  (0.0ms) rollback transaction
1944
+  (0.0ms) begin transaction
1945
+  (0.0ms) rollback transaction
1946
+  (0.0ms) begin transaction
1947
+  (0.0ms) rollback transaction
1948
+  (0.0ms) begin transaction
1949
+  (0.0ms) rollback transaction
1950
+  (0.0ms) begin transaction
1951
+  (0.0ms) rollback transaction
1952
+  (0.0ms) begin transaction
1953
+  (0.0ms) rollback transaction
1954
+  (0.0ms) begin transaction
1955
+  (0.0ms) rollback transaction
1956
+  (0.0ms) begin transaction
1957
+  (0.0ms) rollback transaction
1958
+  (0.0ms) begin transaction
1959
+  (0.0ms) rollback transaction
1960
+  (0.0ms) begin transaction
1961
+  (0.1ms) rollback transaction
1962
+  (0.1ms) begin transaction
1963
+  (0.0ms) SAVEPOINT active_record_1
1964
+ DocumentNumber::DocumentNumber Load (0.2ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1965
+ SQLite3::SQLException: no such table: document_numbers: SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
1966
+  (0.0ms) ROLLBACK TO SAVEPOINT active_record_1
1967
+  (0.0ms) rollback transaction
1968
+  (0.3ms) begin transaction
1969
+  (0.0ms) SAVEPOINT active_record_1
1970
+ DocumentNumber::DocumentNumber Load (0.3ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'invoice' LIMIT 1
1971
+ SQLite3::SQLException: no such table: document_numbers: SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'invoice' LIMIT 1
1972
+  (0.1ms) ROLLBACK TO SAVEPOINT active_record_1
1973
+  (0.1ms) rollback transaction
1974
+  (0.1ms) begin transaction
1975
+  (0.0ms) rollback transaction
1976
+  (0.0ms) begin transaction
1977
+  (0.0ms) rollback transaction
1978
+  (0.0ms) begin transaction
1979
+  (0.0ms) rollback transaction
1980
+  (0.0ms) begin transaction
1981
+  (0.0ms) SAVEPOINT active_record_1
1982
+ DocumentNumber::DocumentNumber Load (0.2ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1983
+ SQLite3::SQLException: no such table: document_numbers: SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'price_adjustment' LIMIT 1
1984
+  (0.0ms) ROLLBACK TO SAVEPOINT active_record_1
1985
+  (0.0ms) rollback transaction
1986
+  (0.1ms) begin transaction
1987
+  (0.0ms) rollback transaction
1988
+  (0.0ms) begin transaction
1989
+  (0.0ms) rollback transaction
1990
+  (0.0ms) begin transaction
1991
+  (0.0ms) rollback transaction
1992
+  (0.0ms) begin transaction
1993
+  (0.0ms) rollback transaction
1994
+  (0.1ms) begin transaction
1995
+  (0.0ms) rollback transaction
1996
+  (0.1ms) begin transaction
1997
+  (0.0ms) rollback transaction
1998
+  (0.0ms) begin transaction
1999
+  (0.0ms) rollback transaction
2000
+  (0.0ms) begin transaction
2001
+  (0.0ms) rollback transaction
2002
+  (0.0ms) begin transaction
2003
+  (0.0ms) rollback transaction
2004
+  (0.0ms) begin transaction
2005
+  (0.0ms) rollback transaction
2006
+  (0.0ms) begin transaction
2007
+  (0.0ms) rollback transaction
2008
+  (0.0ms) begin transaction
2009
+  (0.1ms) SAVEPOINT active_record_1
2010
+ DocumentNumber::DocumentNumber Load (0.2ms) SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
2011
+ SQLite3::SQLException: no such table: document_numbers: SELECT "document_numbers".* FROM "document_numbers" WHERE "document_numbers"."document" = 'inventory' LIMIT 1
2012
+  (0.0ms) ROLLBACK TO SAVEPOINT active_record_1
2013
+  (0.0ms) rollback transaction
2014
+  (1.2ms) CREATE TABLE "document_numbers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "document" varchar(255), "number" integer DEFAULT 1 NOT NULL, "created_at" datetime) 
2015
+  (0.1ms) select sqlite_version(*)
2016
+  (0.9ms) CREATE UNIQUE INDEX "index_document_numbers_on_document" ON "document_numbers" ("document")
2017
+  (0.9ms) CREATE TABLE "inventories" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "number" varchar(255), "created_at" datetime, "updated_at" datetime)
2018
+  (0.9ms) CREATE TABLE "invoices" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "number" varchar(255), "created_at" datetime, "updated_at" datetime) 
2019
+  (0.9ms) CREATE TABLE "price_adjustments" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "document_number" varchar(255), "created_at" datetime, "updated_at" datetime)
2020
+  (1.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
2021
+  (1.0ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
2022
+  (0.1ms) SELECT version FROM "schema_migrations"
2023
+  (0.9ms) INSERT INTO "schema_migrations" (version) VALUES ('20140610093243')
2024
+  (1.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20140610080445')
2025
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20140610090526')
2026
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('20140610093227')
@@ -0,0 +1,140 @@
1
+ require 'spec_helper'
2
+
3
+ describe SupplierComplaint do
4
+ context 'without prefix' do
5
+ before do
6
+ SupplierComplaint.has_document_number(prefix: nil, start: 500)
7
+ end
8
+
9
+ it 'uses default column' do
10
+ supplier_complaint = SupplierComplaint.create
11
+ expect(supplier_complaint.number).not_to be_nil
12
+ end
13
+
14
+ it 'starts from predefined value' do
15
+ supplier_complaint = SupplierComplaint.create(text: 'some')
16
+ expect(supplier_complaint.number).to eq('500')
17
+ end
18
+
19
+ it 'has sequence of numbers' do
20
+ supplier_complaint1 = SupplierComplaint.create(text: 'complaint1')
21
+ supplier_complaint2 = SupplierComplaint.create(text: 'complaint2')
22
+ expect(supplier_complaint1.number).to eq('500')
23
+ expect(supplier_complaint2.number).to eq('501')
24
+ end
25
+
26
+ context 'validation fails' do
27
+ it 'next record gets correct number' do
28
+ supplier_complaint1 = SupplierComplaint.create(text: 'complaint1')
29
+ supplier_complaint2 = SupplierComplaint.create(text: '')
30
+ supplier_complaint3 = SupplierComplaint.create(text: 'complaint3')
31
+ expect(supplier_complaint1.number).to eq('500')
32
+ expect(supplier_complaint2).to be_invalid
33
+ expect(supplier_complaint3.number).to eq('501')
34
+ end
35
+
36
+ it 'next records get correct number' do
37
+ supplier_complaint1 = SupplierComplaint.create(text: '')
38
+ supplier_complaint2 = SupplierComplaint.create(text: 'complaint2')
39
+ supplier_complaint3 = SupplierComplaint.create(text: 'complaint3')
40
+ expect(supplier_complaint1).to be_invalid
41
+ expect(supplier_complaint2.number).to eq('500')
42
+ expect(supplier_complaint3.number).to eq('501')
43
+ end
44
+ end
45
+
46
+ it 'gets array of numbers' do
47
+ expect(SupplierComplaint.get_numbers(3)).to eq(%w(500 501 502))
48
+ end
49
+
50
+ context 'has with_number' do
51
+ it 'assigns number after initialization' do
52
+ expect(SupplierComplaint.new(with_number: true).number).to eq('500')
53
+ end
54
+ end
55
+
56
+ it 'does not assign number after initialization' do
57
+ expect(SupplierComplaint.new.number).to be_nil
58
+ end
59
+ end
60
+
61
+ context 'with prefix' do
62
+ before do
63
+ SupplierComplaint.has_document_number(prefix: 'prefix/', start: 500)
64
+ end
65
+
66
+ it 'uses default column' do
67
+ supplier_complaint = SupplierComplaint.create
68
+ expect(supplier_complaint.number).not_to be_nil
69
+ end
70
+
71
+ it 'starts from predefined value' do
72
+ supplier_complaint = SupplierComplaint.create(text: 'some')
73
+ expect(supplier_complaint.number).to eq('prefix/500')
74
+ end
75
+
76
+ it 'has sequence of numbers' do
77
+ supplier_complaint1 = SupplierComplaint.create(text: 'complaint1')
78
+ supplier_complaint2 = SupplierComplaint.create(text: 'complaint2')
79
+ expect(supplier_complaint1.number).to eq('prefix/500')
80
+ expect(supplier_complaint2.number).to eq('prefix/501')
81
+ end
82
+
83
+ context 'validation fails' do
84
+ it 'next record gets correct number' do
85
+ supplier_complaint1 = SupplierComplaint.create(text: 'complaint1')
86
+ supplier_complaint2 = SupplierComplaint.create(text: '')
87
+ supplier_complaint3 = SupplierComplaint.create(text: 'complaint3')
88
+ expect(supplier_complaint1.number).to eq('prefix/500')
89
+ expect(supplier_complaint2).to be_invalid
90
+ expect(supplier_complaint3.number).to eq('prefix/501')
91
+ end
92
+ end
93
+
94
+ it 'gets array of numbers' do
95
+ expect(SupplierComplaint.get_numbers(3)).to eq(%w(prefix/500 prefix/501 prefix/502))
96
+ end
97
+
98
+ context 'has with_number' do
99
+ it 'assigns number after initialization' do
100
+ expect(SupplierComplaint.new(with_number: true).number).to eq('prefix/500')
101
+ end
102
+ end
103
+
104
+ it 'does not assign number after initialization' do
105
+ expect(SupplierComplaint.new.number).to be_nil
106
+ end
107
+ end
108
+
109
+ context '#update_document_number' do
110
+ before do
111
+ SupplierComplaint.has_document_number(prefix: nil, start: 500)
112
+ SupplierComplaint.create!(text: 'complaint')
113
+ end
114
+
115
+ context 'new number is greater or equal then old' do
116
+ it 'updates number' do
117
+ result = SupplierComplaint.update_document_number(505)
118
+ document_row = DocumentNumber::DocumentNumber.find_by_document('supplier_complaint')
119
+ expect(result).to be true
120
+ expect(document_row.number).to eq 505
121
+ end
122
+
123
+ it 'updates number if new number equals to old' do
124
+ result = SupplierComplaint.update_document_number(501)
125
+ document_row = DocumentNumber::DocumentNumber.find_by_document('supplier_complaint')
126
+ expect(result).to be true
127
+ expect(document_row.number).to eq 501
128
+ end
129
+ end
130
+
131
+ context 'new number is less then old' do
132
+ it 'not updating number' do
133
+ result = SupplierComplaint.update_document_number(400)
134
+ document_row = DocumentNumber::DocumentNumber.find_by_document('supplier_complaint')
135
+ expect(result).to be false
136
+ expect(document_row.number).to eq 501
137
+ end
138
+ end
139
+ end
140
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: document_number
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeny Pavlov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-25 00:00:00.000000000 Z
11
+ date: 2015-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -183,6 +183,7 @@ files:
183
183
  - spec/dummy/app/models/inventory.rb
184
184
  - spec/dummy/app/models/invoice.rb
185
185
  - spec/dummy/app/models/price_adjustment.rb
186
+ - spec/dummy/app/models/supplier_complaint.rb
186
187
  - spec/dummy/app/views/layouts/application.html.erb
187
188
  - spec/dummy/bin/bundle
188
189
  - spec/dummy/bin/rails
@@ -210,6 +211,7 @@ files:
210
211
  - spec/dummy/db/migrate/20140610090526_create_inventories.rb
211
212
  - spec/dummy/db/migrate/20140610093227_create_invoices.rb
212
213
  - spec/dummy/db/migrate/20140610093243_create_price_adjustments.rb
214
+ - spec/dummy/db/migrate/20150617152432_supplier_complaints.rb
213
215
  - spec/dummy/db/schema.rb
214
216
  - spec/dummy/db/test.sqlite3
215
217
  - spec/dummy/log/development.log
@@ -221,6 +223,7 @@ files:
221
223
  - spec/models/inventory_spec.rb
222
224
  - spec/models/invoices_spec.rb
223
225
  - spec/models/price_adjustment_spec.rb
226
+ - spec/models/supplier_complaint_spec.rb
224
227
  - spec/spec_helper.rb
225
228
  homepage: https://github.com/7Pikes/document_number
226
229
  licenses:
@@ -242,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
245
  version: '0'
243
246
  requirements: []
244
247
  rubyforge_project:
245
- rubygems_version: 2.4.0
248
+ rubygems_version: 2.4.5
246
249
  signing_key:
247
250
  specification_version: 4
248
251
  summary: Automatic document number assignment
@@ -254,6 +257,7 @@ test_files:
254
257
  - spec/dummy/app/models/inventory.rb
255
258
  - spec/dummy/app/models/invoice.rb
256
259
  - spec/dummy/app/models/price_adjustment.rb
260
+ - spec/dummy/app/models/supplier_complaint.rb
257
261
  - spec/dummy/app/views/layouts/application.html.erb
258
262
  - spec/dummy/bin/bundle
259
263
  - spec/dummy/bin/rails
@@ -281,6 +285,7 @@ test_files:
281
285
  - spec/dummy/db/migrate/20140610090526_create_inventories.rb
282
286
  - spec/dummy/db/migrate/20140610093227_create_invoices.rb
283
287
  - spec/dummy/db/migrate/20140610093243_create_price_adjustments.rb
288
+ - spec/dummy/db/migrate/20150617152432_supplier_complaints.rb
284
289
  - spec/dummy/db/schema.rb
285
290
  - spec/dummy/db/test.sqlite3
286
291
  - spec/dummy/log/development.log
@@ -294,5 +299,5 @@ test_files:
294
299
  - spec/models/inventory_spec.rb
295
300
  - spec/models/invoices_spec.rb
296
301
  - spec/models/price_adjustment_spec.rb
302
+ - spec/models/supplier_complaint_spec.rb
297
303
  - spec/spec_helper.rb
298
- has_rdoc: