Skip to content

Commit

Permalink
Merge pull request #8 from Stex/release/0.3.0
Browse files Browse the repository at this point in the history
Release/0.3.0
  • Loading branch information
stex committed Jul 18, 2018
2 parents 6309a0e + bf05218 commit c8a2814
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ tmp
*.a
mkmf.log

#Rubymine
.idea
# RVM
.ruby-version

#Dummy Application
test/dummy/log
Expand Down
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ rvm:
- 2.2
- 2.3.1

env:
- DISABLE_DATABASE_ENVIRONMENT_CHECK=1

before_install: 'gem install bundler'
script: 'bundle exec rake'

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 0.3.0

* Fixed a bug that caused setting accessors not being initialized when being called as part of a rake task chain (#6)
11 changes: 1 addition & 10 deletions lib/setting_accessors/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,11 @@ module ClassMethods
# setting and return +nil+ if none was specified previously.
#
def setting_accessor(setting_name, options = {})
#If the database table does not yet exist,
return unless self.table_exists?

fallback = options.delete(:fallback)

SettingAccessors::Internal.set_class_setting(self, setting_name, options)

setting_type = SettingAccessors::Internal.setting_value_type(setting_name, self.new).to_sym

#Create a virtual column in the models column hash.
#This is currently not absolutely necessary, but will become important once
#Time etc. are supported. Otherwise, Rails won't be able to e.g. automatically
#create multi-param fields in forms.
self.columns_hash[setting_name.to_s] = OpenStruct.new(type: setting_type)
setting_type = SettingAccessors::Internal.setting_value_type(setting_name, self).to_sym

#Add the setting's name to the list of setting_accessors for this class
SettingAccessors::Internal.add_setting_accessor_name(self, setting_name)
Expand Down
8 changes: 6 additions & 2 deletions lib/setting_accessors/internal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ def self.set_class_setting(klass, setting_name, options = {})
# - If it's a setting defined in a setting_accessor call, the information is taken from this call
# - Otherwise, an empty hash is returned
#
def self.setting_data(setting_name, assignable = nil)
(assignable && self.get_class_setting(assignable.class, setting_name)) ||
def self.setting_data(setting_name, assignable_class = nil)
# As a convenience function (and to keep the existing code working),
# it is possible to provide a class or an instance of said class
assignable_class &&= assignable_class.class unless assignable_class.is_a?(Class)

(assignable_class && self.get_class_setting(assignable_class, setting_name)) ||
self.global_config[setting_name.to_s] ||
{}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/setting_accessors/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SettingAccessors
VERSION = '0.2.0'.freeze
VERSION = '0.3.0'.freeze
end
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
end

# configure shoulda matchers
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :minitest
with.library :rails
end
end

# For generators
require "rails/generators/test_case"
require "generators/setting_accessors/install_generator"

0 comments on commit c8a2814

Please sign in to comment.