static-record 1.0.0.pre.3 → 1.0.0.pre.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +34 -1
  3. data/Rakefile +1 -1
  4. data/lib/static_record.rb +5 -1
  5. data/lib/static_record/concerns/query_building_concern.rb +8 -7
  6. data/lib/static_record/exceptions.rb +1 -0
  7. data/lib/static_record/migrations/has_static_record.rb +52 -0
  8. data/lib/static_record/migrations/railtie.rb +16 -0
  9. data/lib/static_record/migrations/schema.rb +49 -0
  10. data/lib/static_record/models/predicates.rb +20 -6
  11. data/lib/static_record/models/querying.rb +8 -0
  12. data/lib/static_record/models/relation.rb +15 -2
  13. data/lib/static_record/version.rb +1 -1
  14. data/spec/helpers/migration_has_been_run.rb +28 -0
  15. data/spec/migrations/railtie_spec.rb +8 -0
  16. data/spec/models/{static_record/base_spec.rb → base_spec.rb} +0 -0
  17. data/spec/models/{static_record/querying_spec.rb → querying_spec.rb} +12 -1
  18. data/spec/models/{static_record/relation_spec.rb → relation_spec.rb} +0 -0
  19. data/spec/rails_helper.rb +1 -0
  20. data/spec/spec_helper.rb +5 -0
  21. data/spec/test_app/app/models/article.rb +4 -3
  22. data/spec/test_app/app/models/articles/article_four.rb +1 -0
  23. data/spec/test_app/app/models/articles/article_one.rb +1 -0
  24. data/spec/test_app/app/models/articles/article_three.rb +1 -0
  25. data/spec/test_app/app/models/articles/article_two.rb +1 -0
  26. data/spec/test_app/app/models/role.rb +2 -1
  27. data/spec/test_app/app/models/test.rb +3 -0
  28. data/spec/test_app/db/migrate/20161229011421_create_test.rb +7 -0
  29. data/spec/test_app/db/migrate/20161229011439_bind_article_to_test.rb +5 -0
  30. data/spec/test_app/db/schema.rb +6 -1
  31. data/spec/test_app/spec/bind_article_to_test_spec.rb +12 -0
  32. data/spec/test_app/spec/has_static_record_spec.rb +22 -0
  33. metadata +52 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a3706048403361650a6116e13d8e88d6afd574d
4
- data.tar.gz: e3576955961ae0c8f612feae91608eb589e718cd
3
+ metadata.gz: b60c1fa4bbb64488ee835ee71ca5b98a2d4ac0ec
4
+ data.tar.gz: bbc16fa804ca8c6e53ad8af528b0e24951ee701d
5
5
  SHA512:
6
- metadata.gz: 22b0f67f4373b06df4555dbbb99464b914414a8c9e6c21d383964959efd17d7d179a560c5f9ec4597e5124b8555dd72c895e7c84f7b12cbfec8f2d15beb1a5c5
7
- data.tar.gz: 57fe5f972a3c944fb0ebb17a2cfddc6d53c3c4ba03951e2ca8928a8052c140f3b3fddfe747b51f0d82dd6b97369f68f5fc71ac2fa0079bbe10e9e803d00dabc6
6
+ metadata.gz: 3422bf6fc4b9119a593a109414741e53f8b97b1a93a9fac9a3ca57df30dc7b2f41b72526e02489648d54d6d2f8ffc76db81229290ca127b810f7d618d8736d28
7
+ data.tar.gz: a97badf91f4997632dc5e3b1e0485cd7a41356af27f85b8dc7cc8986deded9d616d9ea7ba060dd6b220d72d3b5b728e2072f218ebd74c37f10b4fe546a923fc0
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = StaticRecord
2
2
 
3
- {<img src="https://badge.fury.io/rb/static-record.svg" alt="Gem Version" />}[https://badge.fury.io/rb/static-record] {<img src="https://codeclimate.com/github/hchevalier/static_record/badges/gpa.svg" />}[https://codeclimate.com/github/hchevalier/static_record] {<img src="https://travis-ci.org/hchevalier/static_record.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/hchevalier/static_record]
3
+ {<img src="https://badge.fury.io/rb/static-record.svg" alt="Gem Version" />}[https://badge.fury.io/rb/static-record] {<img src="https://codeclimate.com/github/hchevalier/static_record/badges/gpa.svg" />}[https://codeclimate.com/github/hchevalier/static_record] {<img src="https://codeclimate.com/github/hchevalier/static_record/badges/coverage.svg" />}[https://codeclimate.com/github/hchevalier/static_record/coverage] {<img src="https://travis-ci.org/hchevalier/static_record.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/hchevalier/static_record]
4
4
 
5
5
  StaticRecord allows you to perform ActiveRecord-like queries over ruby files.
6
6
 
@@ -105,6 +105,39 @@ Records are being assigned an ID in the SQLite3 database when inserted.
105
105
 
106
106
  As the database is recreated at each application startup and IDs depend on the insertion order, I advise you to rely on another column if you want to hardcode a specific record somewhere in your app.
107
107
 
108
+ == References
109
+
110
+ A migration helper allows your ActiveRecord models to reference a StaticRecord.
111
+
112
+ In a migration, use:
113
+
114
+ def change
115
+ bind_static_record :users, :article
116
+ end
117
+
118
+ In your model, you can use
119
+
120
+ has_static_record :article
121
+
122
+ You can now do
123
+
124
+ u = User.first
125
+ u.article = Article.find('Article One')
126
+ u.save
127
+
128
+ u = User.first
129
+ u.article
130
+
131
+ If you don't want to name your column with the same name than your StaticRecord base, you can do as follow
132
+
133
+ # In the migration
134
+ def change
135
+ bind_static_record :users, :any_column_name
136
+ end
137
+
138
+ # In the model
139
+ has_static_record :any_column_name, class_name: 'Article'
140
+
108
141
  == Questions?
109
142
 
110
143
  If you have any question or doubt regarding StaticRecord which you cannot find the solution to in the documentation, you can send me an email. I'll try to answer in less than 24 hours.
data/Rakefile CHANGED
@@ -27,4 +27,4 @@ require 'rspec/core/rake_task'
27
27
  RSpec::Core::RakeTask.new(:spec) do |t|
28
28
  t.pattern = Dir.glob('../spec/**/*_spec.rb')
29
29
  end
30
- task :default => :spec
30
+ task default: :spec
data/lib/static_record.rb CHANGED
@@ -9,5 +9,9 @@ require 'static_record/models/querying'
9
9
  require 'static_record/models/relation'
10
10
  require 'static_record/models/base'
11
11
 
12
- module StaticRecord
12
+ require 'static_record/migrations/schema'
13
+ require 'static_record/migrations/railtie'
14
+ require 'static_record/migrations/has_static_record'
15
+
16
+ module StaticRecord # :nodoc:
13
17
  end
@@ -14,7 +14,7 @@ module StaticRecord
14
14
  private
15
15
 
16
16
  def sql_select_from
17
- sql = "SELECT #{@columns} FROM #{@table}"
17
+ "SELECT #{@columns} FROM #{@table}"
18
18
  end
19
19
 
20
20
  def sql_where
@@ -22,16 +22,18 @@ module StaticRecord
22
22
  end
23
23
 
24
24
  def sql_order
25
+ return '' unless @primary_key
26
+
25
27
  ord_sql = ''
26
28
  @order_by.each do |ord|
27
29
  ord_sql += ord_sql.empty? ? ' ORDER BY' : ', '
28
30
  case ord.class.name
29
31
  when Hash.name
30
- ord_sql += ord.map { |k, v| " #{@table}.#{k.to_s} #{v.to_s.upcase}" }.join(',')
32
+ ord_sql += ord.map { |k, v| " #{@table}.#{k} #{v.to_s.upcase}" }.join(',')
31
33
  when Array.name
32
- ord_sql += ord.map { |sym| " #{@table}.#{sym.to_s} ASC" }.join(',')
34
+ ord_sql += ord.map { |sym| " #{@table}.#{sym} ASC" }.join(',')
33
35
  when Symbol.name
34
- ord_sql += " #{@table}.#{ord.to_s} ASC"
36
+ ord_sql += " #{@table}.#{ord} ASC"
35
37
  when String.name
36
38
  ord_sql += " #{ord}"
37
39
  end
@@ -67,18 +69,17 @@ module StaticRecord
67
69
  def where_clause_from_hash(clause, subquery)
68
70
  parts = subquery.keys.map do |key|
69
71
  value = subquery[key]
70
- part = ''
71
72
  if value.is_a?(Array)
72
73
  # ex: where(name: ['John', 'Jack'])
73
74
  # use IN operator
74
75
  value.map! { |v| v =~ /^\d+$/ ? v : "\"#{v}\"" }
75
76
  inverse = 'NOT ' if clause[:operator] == :not_eq
76
- part = "#{key.to_s} #{inverse}IN (#{value.join(',')})"
77
+ "#{key} #{inverse}IN (#{value.join(',')})"
77
78
  else
78
79
  # ex: where(name: 'John')
79
80
  # use = operator
80
81
  inverse = '!' if clause[:operator] == :not_eq
81
- part = "#{key.to_s} #{inverse}= '#{value}'"
82
+ "#{key} #{inverse}= '#{value}'"
82
83
  end
83
84
  end
84
85
  parts.join(' AND ')
@@ -3,4 +3,5 @@ module StaticRecord
3
3
  class ReservedAttributeName < RuntimeError; end
4
4
  class NoPrimaryKey < RuntimeError; end
5
5
  class UnkownType < RuntimeError; end
6
+ class ClassError < RuntimeError; end
6
7
  end
@@ -0,0 +1,52 @@
1
+ module StaticRecord
2
+ # Provides has_static_record when included
3
+ module HasStaticRecord
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods # :nodoc:
9
+ def has_static_record(table_name, options = nil)
10
+ options ||= {}
11
+ class_eval do
12
+ define_setter(table_name, options)
13
+ define_getter(table_name, options)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def define_setter(table_name, options)
20
+ define_method("#{table_name}=") do |static_record|
21
+ unless static_record.class.pkey
22
+ err = "No primary key has been defined for #{static_record.class}"
23
+ raise NoPrimaryKey, err
24
+ end
25
+
26
+ table = __method__.to_s.delete('=')
27
+ options[:class_name] ||= table.camelize
28
+ superklass = static_record.class.superclass
29
+ unless superklass.to_s == options[:class_name]
30
+ err = "Record must be an instance of #{options[:class_name]}"
31
+ raise ClassError, err
32
+ end
33
+
34
+ send(:"#{table}_static_record_type=", static_record.class.name)
35
+ end
36
+ end
37
+
38
+ def define_getter(table_name, options)
39
+ define_method(table_name) do
40
+ table = __method__.to_s
41
+ record_type = send(:"#{table}_static_record_type")
42
+ return nil unless record_type
43
+
44
+ options[:class_name] ||= table.camelize
45
+ # eager loading may be disabled, initialize parent class
46
+ superklass = options[:class_name].constantize
47
+ superklass.find_by(klass: record_type)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,16 @@
1
+ module StaticRecord
2
+ class Railtie < Rails::Railtie # :nodoc:
3
+ initializer 'static_record.insert_into_active_record' do |_app|
4
+ ActiveSupport.on_load :active_record do
5
+ StaticRecord::Railtie.insert
6
+ end
7
+ end
8
+
9
+ def self.insert
10
+ if defined?(ActiveRecord)
11
+ ActiveRecord::Base.send(:include, StaticRecord::Schema)
12
+ ActiveRecord::Base.send(:include, StaticRecord::HasStaticRecord)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,49 @@
1
+ module StaticRecord
2
+ # Provides helper methods that can be used in migrations
3
+ module Schema
4
+ COLUMNS = {
5
+ static_record_type: :string
6
+ }.freeze
7
+
8
+ def self.included(_base)
9
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.send :include, Statements
10
+ ActiveRecord::Migration::CommandRecorder.send :include, CommandRecorder
11
+ end
12
+
13
+ module Statements # :nodoc:
14
+ def bind_static_record(table_name, *record_tables)
15
+ raise ArgumentError, 'Please specify StaticRecord table in your bind_static_record call.' if record_tables.empty?
16
+
17
+ options = record_tables.extract_options!
18
+ record_tables.each do |record_table|
19
+ COLUMNS.each_pair do |column_name, column_type|
20
+ column_options = options.merge(options[column_name.to_sym] || {})
21
+ add_column(table_name, "#{record_table}_#{column_name}", column_type, column_options)
22
+ end
23
+ end
24
+ end
25
+
26
+ def remove_static_record(table_name, *record_tables)
27
+ raise ArgumentError, 'Please specify StaticRecord table in your remove_static_record call.' if record_tables.empty?
28
+
29
+ record_tables.each do |record_table|
30
+ COLUMNS.keys.each do |column_name|
31
+ remove_column(table_name, "#{record_table}_#{column_name}")
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ module CommandRecorder # :nodoc:
38
+ def bind_static_record(*args)
39
+ record(:bind_static_record, args)
40
+ end
41
+
42
+ private
43
+
44
+ def invert_bind_static_record(args)
45
+ [:remove_static_record, args]
46
+ end
47
+ end
48
+ end
49
+ end
@@ -28,15 +28,29 @@ module StaticRecord
28
28
 
29
29
  def find(value)
30
30
  raise StaticRecord::NoPrimaryKey, 'No primary key have been set' if @primary_key.nil?
31
- @result_type = :record unless value.is_a?(Array)
31
+ unless value.is_a?(Array)
32
+ @result_type = :record
33
+ @sql_limit = 1
34
+ end
32
35
  add_subclause(q: { :"#{@primary_key}" => value })
33
- @sql_limit = 1 if @result_type == :record
34
-
35
36
  res = to_a
36
- return res if @only_sql
37
37
 
38
- raise StaticRecord::RecordNotFound, "Couldn't find all #{@store.singularize.capitalize} with '#{@primary_key.to_s}' IN #{value}" if @result_type == :array && res.size != value.size
39
- raise StaticRecord::RecordNotFound, "Couldn't find #{@store.singularize.capitalize} with '#{@primary_key.to_s}'=#{value}" if @result_type == :record && res.nil?
38
+ unless @only_sql
39
+ case @result_type
40
+ when :array
41
+ if res.size != value.size
42
+ err = "Couldn't find all #{@store.singularize.capitalize} "\
43
+ "with '#{@primary_key}' IN #{value}"
44
+ raise StaticRecord::RecordNotFound, err
45
+ end
46
+ when :record
47
+ if res.nil?
48
+ err = "Couldn't find #{@store.singularize.capitalize} "\
49
+ "with '#{@primary_key}'=#{value}"
50
+ raise StaticRecord::RecordNotFound, err
51
+ end
52
+ end
53
+ end
40
54
 
41
55
  res
42
56
  end
@@ -20,6 +20,14 @@ module StaticRecord
20
20
  super
21
21
  end
22
22
  end
23
+
24
+ def respond_to_missing?(method_sym, include_private = false)
25
+ if Relation.new(nil, store: store).respond_to_missing?(method_sym, true)
26
+ true
27
+ else
28
+ super
29
+ end
30
+ end
23
31
  end
24
32
  end
25
33
  end
@@ -47,6 +47,10 @@ module StaticRecord
47
47
  end
48
48
  end
49
49
 
50
+ def respond_to_missing?(method_sym, include_private = false)
51
+ include_private ? super : respond_to?(method_sym, true)
52
+ end
53
+
50
54
  private
51
55
 
52
56
  def chained_from(relation)
@@ -74,10 +78,15 @@ module StaticRecord
74
78
  def exec_request(expectancy = :result_set)
75
79
  return build_query if @only_sql
76
80
 
77
- error = nil
81
+ dbname = Rails.root.join('db', "static_#{@store}.sqlite3").to_s
82
+ result = get_expected_result_from_database(dbname, expectancy)
83
+ cast_result(expectancy, result)
84
+ end
85
+
86
+ def get_expected_result_from_database(dbname, expectancy)
78
87
  result = nil
88
+
79
89
  begin
80
- dbname = Rails.root.join('db', "static_#{@store}.sqlite3").to_s
81
90
  db = SQLite3::Database.open(dbname)
82
91
  if expectancy == :integer
83
92
  result = db.get_first_value(build_query)
@@ -95,6 +104,10 @@ module StaticRecord
95
104
 
96
105
  raise error if error
97
106
 
107
+ result
108
+ end
109
+
110
+ def cast_result(expectancy, result)
98
111
  if expectancy == :result_set
99
112
  case @result_type
100
113
  when :array
@@ -1,3 +1,3 @@
1
1
  module StaticRecord
2
- VERSION = '1.0.0.pre.3'.freeze
2
+ VERSION = '1.0.0.pre.4'.freeze
3
3
  end
@@ -0,0 +1,28 @@
1
+ def migration_has_been_run?(version)
2
+ table_name = ActiveRecord::Migrator.schema_migrations_table_name
3
+ query = "SELECT version FROM %s WHERE version = '%s'" % [table_name, version]
4
+ ActiveRecord::Base.connection.clear_query_cache
5
+ ActiveRecord::Base.connection.execute(query).any?
6
+ end
7
+
8
+ def test_migrate(migration_class, migration_number, way, reset_classes = nil)
9
+ reset_classes ||= []
10
+
11
+ verbosity = ActiveRecord::Migration.verbose
12
+ ActiveRecord::Migration.verbose = false
13
+
14
+ migration = migration_class.new
15
+ case way
16
+ when :up
17
+ migration.migrate(:up)# unless migration_has_been_run?(migration_number)
18
+ when :down
19
+ migration.migrate(:down)# if migration_has_been_run?(migration_number)
20
+ end
21
+
22
+ reset_classes.each do |klass|
23
+ klass.connection.schema_cache.clear!
24
+ klass.reset_column_information
25
+ end
26
+
27
+ ActiveRecord::Migration.verbose = verbosity
28
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'rails_helper'
3
+
4
+ RSpec.describe StaticRecord::Railtie, :type => :module do
5
+ it 'extends ActiveRecord::Base' do
6
+ expect{ActiveRecord::Base.has_static_record(:test)}.not_to raise_error
7
+ end
8
+ end
@@ -1,7 +1,18 @@
1
1
  require 'spec_helper'
2
2
  require 'rails_helper'
3
3
 
4
- RSpec.describe StaticRecord::Querying, :type => :model do
4
+ RSpec.describe StaticRecord::Querying, :type => :module do
5
+ it 'responds to \'ActiveRecord\' methods through StaticRecord::Relation' do
6
+ expect(Article.methods.include?(:where)).to be false
7
+ expect(Article.respond_to?(:where)).to be true
8
+ expect(Article.respond_to_missing?(:where)).to be true
9
+ end
10
+
11
+ it 'asks superclass for other methods' do
12
+ expect(Article.respond_to?(:inexisting_method)).to be false
13
+ expect(Article.respond_to_missing?(:inexisting_method)).to be false
14
+ end
15
+
5
16
  it 'delegates requests to StaticRecord::Relation' do
6
17
  expect(Article.where(author: 'The author')).to be_a(StaticRecord::Relation)
7
18
  end
data/spec/rails_helper.rb CHANGED
@@ -6,6 +6,7 @@ require 'spec_helper'
6
6
  require 'rspec/rails'
7
7
 
8
8
  ActiveRecord::Migration.maintain_test_schema!
9
+ require 'helpers/migration_has_been_run'
9
10
 
10
11
  RSpec.configure do |config|
11
12
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,9 @@
1
1
  RSpec.configure do |config|
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter '/spec/'
5
+ end
6
+
2
7
  config.expect_with :rspec do |expectations|
3
8
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4
9
  end
@@ -3,7 +3,8 @@ class Article < StaticRecord::Base
3
3
  path Rails.root.join('app', 'models', 'articles', '**', '*.rb')
4
4
  primary_key :name
5
5
 
6
- columns name: :string,
7
- author: :string,
8
- rank: :integer
6
+ columns name: :string,
7
+ author: :string,
8
+ rank: :integer,
9
+ important: :boolean
9
10
  end
@@ -2,4 +2,5 @@ class ArticleFour < Article
2
2
  attribute :name, 'Article Four'
3
3
  attribute :author, 'Me'
4
4
  attribute :rank, 3
5
+ attribute :important, false
5
6
  end
@@ -2,4 +2,5 @@ class ArticleOne < Article
2
2
  attribute :name, 'Article One'
3
3
  attribute :author, 'The author'
4
4
  attribute :rank, 2
5
+ attribute :important, false
5
6
  end
@@ -2,4 +2,5 @@ class ArticleThree < Article
2
2
  attribute :name, 'Article Three'
3
3
  attribute :author, 'Another author'
4
4
  attribute :rank, 1
5
+ attribute :important, true
5
6
  end
@@ -2,4 +2,5 @@ class ArticleTwo < Article
2
2
  attribute :name, 'Article Two'
3
3
  attribute :author, 'The author'
4
4
  attribute :rank, 3
5
+ attribute :important, true
5
6
  end
@@ -1,5 +1,6 @@
1
1
  class Role < StaticRecord::Base
2
2
  table :roles
3
3
  path Rails.root.join('app', 'models', 'roles', '**', '*.rb')
4
- columns [:name, :description]
4
+ columns name: :string,
5
+ description: :string
5
6
  end
@@ -0,0 +1,3 @@
1
+ class Test < ActiveRecord::Base
2
+ has_static_record :article
3
+ end
@@ -0,0 +1,7 @@
1
+ class CreateTest < ActiveRecord::Migration
2
+ def change
3
+ create_table :tests do |t|
4
+ t.string :name
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class BindArticleToTest < ActiveRecord::Migration
2
+ def change
3
+ bind_static_record :tests, :article
4
+ end
5
+ end
@@ -11,6 +11,11 @@
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: 0) do
14
+ ActiveRecord::Schema.define(version: 20161229011439) do
15
+
16
+ create_table "tests", force: :cascade do |t|
17
+ t.string "name"
18
+ t.string "article_static_record_type"
19
+ end
15
20
 
16
21
  end
@@ -0,0 +1,12 @@
1
+ load Rails.root.join('db', 'migrate', '20161229011439_bind_article_to_test.rb')
2
+
3
+ RSpec.describe BindArticleToTest, :type => :migration do
4
+ describe '.up' do
5
+ it 'adds a column to store a StaticRecord relation' do
6
+ test_migrate(BindArticleToTest, '20161229011439', :down, [Test])
7
+ expect { Test.new.article_static_record_type }.to raise_error(NoMethodError)
8
+ test_migrate(BindArticleToTest, '20161229011439', :up, [Test])
9
+ expect { Test.new.article_static_record_type }.not_to raise_error
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'rails_helper'
3
+
4
+ RSpec.describe StaticRecord::HasStaticRecord, :type => :module do
5
+ it 'adds a setter to ActiveRecord' do
6
+ t = Test.new(name: 'Test')
7
+ t.article = Article.find('Article One')
8
+ expect(t.article_static_record_type).to eql('ArticleOne')
9
+ end
10
+
11
+ it 'adds a getter to ActiveRecord' do
12
+ article = Article.find('Article One')
13
+ Test.create(name: 'Test', article: article)
14
+ t = Test.last
15
+ expect(t.article.name).to eql(article.name)
16
+ end
17
+
18
+ it 'cannot add getter to ActiveRecord if no primary key is set' do
19
+ Test.has_static_record :role
20
+ expect { Test.new.role = Role.last }.to raise_error
21
+ end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: static-record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.3
4
+ version: 1.0.0.pre.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hugo Chevalier
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: codeclimate-test-reporter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.0.0
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: rubocop
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -120,15 +148,20 @@ files:
120
148
  - lib/static_record/concerns/sqlite_storing_concern.rb
121
149
  - lib/static_record/engine.rb
122
150
  - lib/static_record/exceptions.rb
151
+ - lib/static_record/migrations/has_static_record.rb
152
+ - lib/static_record/migrations/railtie.rb
153
+ - lib/static_record/migrations/schema.rb
123
154
  - lib/static_record/models/base.rb
124
155
  - lib/static_record/models/predicates.rb
125
156
  - lib/static_record/models/querying.rb
126
157
  - lib/static_record/models/relation.rb
127
158
  - lib/static_record/version.rb
128
159
  - lib/tasks/static_record_tasks.rake
129
- - spec/models/static_record/base_spec.rb
130
- - spec/models/static_record/querying_spec.rb
131
- - spec/models/static_record/relation_spec.rb
160
+ - spec/helpers/migration_has_been_run.rb
161
+ - spec/migrations/railtie_spec.rb
162
+ - spec/models/base_spec.rb
163
+ - spec/models/querying_spec.rb
164
+ - spec/models/relation_spec.rb
132
165
  - spec/rails_helper.rb
133
166
  - spec/spec_helper.rb
134
167
  - spec/test_app/app/controllers/application_controller.rb
@@ -140,6 +173,7 @@ files:
140
173
  - spec/test_app/app/models/articles/article_two.rb
141
174
  - spec/test_app/app/models/role.rb
142
175
  - spec/test_app/app/models/roles/role_one.rb
176
+ - spec/test_app/app/models/test.rb
143
177
  - spec/test_app/config/application.rb
144
178
  - spec/test_app/config/boot.rb
145
179
  - spec/test_app/config/environment.rb
@@ -155,7 +189,11 @@ files:
155
189
  - spec/test_app/config/initializers/session_store.rb
156
190
  - spec/test_app/config/initializers/wrap_parameters.rb
157
191
  - spec/test_app/config/routes.rb
192
+ - spec/test_app/db/migrate/20161229011421_create_test.rb
193
+ - spec/test_app/db/migrate/20161229011439_bind_article_to_test.rb
158
194
  - spec/test_app/db/schema.rb
195
+ - spec/test_app/spec/bind_article_to_test_spec.rb
196
+ - spec/test_app/spec/has_static_record_spec.rb
159
197
  homepage: https://github.com/hchevalier/static_record
160
198
  licenses:
161
199
  - MIT
@@ -181,9 +219,11 @@ signing_key:
181
219
  specification_version: 4
182
220
  summary: Static immutable records gem
183
221
  test_files:
184
- - spec/models/static_record/base_spec.rb
185
- - spec/models/static_record/querying_spec.rb
186
- - spec/models/static_record/relation_spec.rb
222
+ - spec/helpers/migration_has_been_run.rb
223
+ - spec/migrations/railtie_spec.rb
224
+ - spec/models/base_spec.rb
225
+ - spec/models/querying_spec.rb
226
+ - spec/models/relation_spec.rb
187
227
  - spec/rails_helper.rb
188
228
  - spec/spec_helper.rb
189
229
  - spec/test_app/app/controllers/application_controller.rb
@@ -195,6 +235,7 @@ test_files:
195
235
  - spec/test_app/app/models/articles/article_two.rb
196
236
  - spec/test_app/app/models/role.rb
197
237
  - spec/test_app/app/models/roles/role_one.rb
238
+ - spec/test_app/app/models/test.rb
198
239
  - spec/test_app/config/application.rb
199
240
  - spec/test_app/config/boot.rb
200
241
  - spec/test_app/config/environment.rb
@@ -210,4 +251,8 @@ test_files:
210
251
  - spec/test_app/config/initializers/session_store.rb
211
252
  - spec/test_app/config/initializers/wrap_parameters.rb
212
253
  - spec/test_app/config/routes.rb
254
+ - spec/test_app/db/migrate/20161229011421_create_test.rb
255
+ - spec/test_app/db/migrate/20161229011439_bind_article_to_test.rb
213
256
  - spec/test_app/db/schema.rb
257
+ - spec/test_app/spec/bind_article_to_test_spec.rb
258
+ - spec/test_app/spec/has_static_record_spec.rb