aform 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a00654d7e27e53fa05173608a7f0630ebe6b771
4
- data.tar.gz: c76a97771dd6d28f781b3b49c243b3634eebc0ca
3
+ metadata.gz: b539a689687d10ce372376c984749ac30cbe65cc
4
+ data.tar.gz: addef8dbcb1055f19ce403ae320c4e37532d6ee3
5
5
  SHA512:
6
- metadata.gz: 82eb7f0087485fdc85a79bfdee55c7f1f24ebf0d8169a53c510a1889e36d337c45829d20d3afdca609f6fcfc792b2ba498fe685d2356060aa77d7b43d1a87d90
7
- data.tar.gz: bc19d70163f31bbf851063a4518b11eec248e509b98ff7ea952214949f32420ca15d556d4b3c376ffeaac6e84713b46978d4ddc1cfd8ce469afff50c4a626291
6
+ metadata.gz: 5b6c8024ce914f97a27845459d2003c18d949974a86703a0e75949d38b1588aeb70da76533464eda580563396bea4942d36e9c6d7d37a7e679ea94a01d4e7f4b
7
+ data.tar.gz: 95fb5e0da238837daf95f78ca910f098b984d700b46d049873571ff20ca2f4214ca98a077fbdd90640a75a3e6d8a7f3df4edfd1273af0d64b1de770dc19b1e83
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0.0-p481"
4
+ - "2.1.2"
5
+ before_script:
6
+ - bundle exec rake test:prepare
7
+ script:
8
+ - bundle exec rake test
9
+ - bundle exec rake test:integration
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
1
  # Aform
2
+ [![Build Status](https://travis-ci.org/antonversal/aform.svg?branch=master)](https://travis-ci.org/antonversal/aform)
3
+
4
+ [![Code Quality](https://codeclimate.com/github/antonversal/aform.png)](https://codeclimate.com/github/antonversal/aform)
2
5
 
3
6
  TODO: Write a gem description
4
7
 
data/Rakefile CHANGED
@@ -11,4 +11,34 @@ Rake::TestTask.new do |t|
11
11
  t.libs << 'test'
12
12
  t.name = "test:integration"
13
13
  t.pattern = 'test/integration/*_test.rb'
14
- end
14
+ end
15
+
16
+ namespace :test do
17
+ desc "Prepare test environment"
18
+ task :prepare do
19
+ require 'active_record'
20
+ ActiveRecord::Base.establish_connection(
21
+ :adapter => "sqlite3",
22
+ :database => "#{Dir.pwd}/database.sqlite3"
23
+ )
24
+
25
+ ActiveRecord::Schema.define do
26
+ create_table :posts do |t|
27
+ t.column :title, :string
28
+ t.column :author, :string
29
+ t.timestamps
30
+ end
31
+
32
+ create_table :comments do |t|
33
+ t.column :message, :string
34
+ t.column :author, :string
35
+ t.belongs_to :post
36
+ end
37
+
38
+ create_table :likes do |t|
39
+ t.column :author, :string
40
+ t.belongs_to :comment
41
+ end
42
+ end
43
+ end
44
+ end
data/lib/aform/form.rb CHANGED
@@ -2,12 +2,12 @@ module Aform
2
2
  class Form
3
3
  class_attribute :params, :pkey, :validations, :nested_form_klasses
4
4
 
5
- attr_reader :form_model, :attributes, :nested_forms, :record, :parent
5
+ attr_reader :form_model, :attributes, :nested_forms, :model, :parent
6
6
 
7
- def initialize(record, attributes, parent = nil, opts = {})
7
+ def initialize(model, attributes, parent = nil, opts = {})
8
8
  @opts = opts
9
9
  @attributes = attributes
10
- @record = record
10
+ @model = model
11
11
  @parent = parent
12
12
  assign_opts_instances
13
13
  initialize_nested
@@ -83,7 +83,7 @@ module Aform
83
83
  @form_saver = @opts[:form_saver] || Aform::FormSaver.new(self)
84
84
  @form_model = @opts[:form_model] || Aform::Model.\
85
85
  build_klass(self.params, self.validations).\
86
- new(record, self, attributes)
86
+ new(model, self, attributes)
87
87
  end
88
88
 
89
89
  def initialize_nested
@@ -92,7 +92,7 @@ module Aform
92
92
  nested_form_klasses.inject({}) do |memo, (k, v)|
93
93
  if attributes[k]
94
94
  nested = attributes[k].map do |attrs|
95
- v.new(nested_record(k, attrs, v.pkey), attrs, self, @opts)
95
+ v.new(nested_model(k, attrs, v.pkey), attrs, self, @opts)
96
96
  end
97
97
  memo.merge(k => nested)
98
98
  else
@@ -102,9 +102,9 @@ module Aform
102
102
  end
103
103
  end
104
104
 
105
- def nested_record(association, attrs, key)
105
+ def nested_model(association, attrs, key)
106
106
  key = key || :id
107
- record.send(association).find_by(key => attrs[key]) || \
107
+ model.send(association).find_by(key => attrs[key]) || \
108
108
  association.to_s.classify.constantize.new
109
109
  end
110
110
  end
@@ -27,7 +27,7 @@ module Aform
27
27
  def save_nested(form)
28
28
  form.nested_forms.map do |k, v|
29
29
  v.map do |nf|
30
- result = nf.form_model.save(form.record.send(k))
30
+ result = nf.form_model.save(form.model.send(k))
31
31
  save_nested(nf) if nf.nested_forms
32
32
  result
33
33
  end
data/lib/aform/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Aform
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -21,10 +21,10 @@ describe Aform::FormSaver do
21
21
  form_model: form_model)
22
22
  end
23
23
 
24
- def mock_form(nested_forms: nil, record: nil, save: true)
24
+ def mock_form(nested_forms: nil, model: nil, save: true)
25
25
  OpenStruct.new(nested_forms: nested_forms,
26
26
  form_model: OpenStruct.new(save: save),
27
- record: record)
27
+ model: model)
28
28
  end
29
29
 
30
30
  def form_saver(form)
@@ -49,14 +49,14 @@ describe Aform::FormSaver do
49
49
  it "success" do
50
50
  nested_forms = [mock_nested_form, mock_nested_form]
51
51
  form = mock_form(nested_forms: {comments: nested_forms},
52
- record: OpenStruct.new(comments: []))
52
+ model: OpenStruct.new(comments: []))
53
53
  form_saver(form).save.must_equal(true)
54
54
  end
55
55
 
56
56
  it "failure" do
57
57
  nested_forms = [mock_nested_form(false), mock_nested_form]
58
58
  form = mock_form(nested_forms: {comments: nested_forms},
59
- record: OpenStruct.new(comments: []))
59
+ model: OpenStruct.new(comments: []))
60
60
  form_saver(form).save.must_equal(false)
61
61
  end
62
62
  end
@@ -7,26 +7,6 @@ ActiveRecord::Base.establish_connection(
7
7
  :database => "#{Dir.pwd}/database.sqlite3"
8
8
  )
9
9
 
10
- #TODO: create task
11
- #ActiveRecord::Schema.define do
12
- # create_table :posts do |t|
13
- # t.column :title, :string
14
- # t.column :author, :string
15
- # t.timestamps
16
- # end
17
- #
18
- # create_table :comments do |t|
19
- # t.column :message, :string
20
- # t.column :author, :string
21
- # t.belongs_to :post
22
- # end
23
- #
24
- # create_table :likes do |t|
25
- # t.column :author, :string
26
- # t.belongs_to :comment
27
- # end
28
- #end
29
-
30
10
  class Post < ActiveRecord::Base
31
11
  has_many :comments
32
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Versal
@@ -172,6 +172,7 @@ extensions: []
172
172
  extra_rdoc_files: []
173
173
  files:
174
174
  - ".gitignore"
175
+ - ".travis.yml"
175
176
  - Gemfile
176
177
  - LICENSE.txt
177
178
  - README.md